Skip to content

Commit c0c6c45

Browse files
committed
Report documentation with error message
1 parent 3d22c38 commit c0c6c45

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/fetch-wrapper.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,22 @@ async function getResponseData(response: Response) {
176176
function toErrorMessage(data: any) {
177177
if (typeof data === "string") return data;
178178

179+
let suffix: string;
180+
181+
// istanbul ignore else - just in case
182+
if ("documentation_url" in data) {
183+
suffix = ` - ${data.documentation_url}`;
184+
} else {
185+
suffix = "";
186+
}
187+
179188
// istanbul ignore else - just in case
180189
if ("message" in data) {
181190
if (Array.isArray(data.errors)) {
182-
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}`;
191+
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`;
183192
}
184193

185-
return data.message;
194+
return `${data.message}${suffix}`;
186195
}
187196

188197
// istanbul ignore next - just in case

test/request.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
809809
.catch((error) => {
810810
expect(error).toHaveProperty(
811811
"message",
812-
`Validation failed: "Only organization repositories can have users and team restrictions", {"resource":"Search","field":"q","code":"invalid"}`,
812+
`Validation failed: "Only organization repositories can have users and team restrictions", {"resource":"Search","field":"q","code":"invalid"} - https://developer.github.com/v3/repos/branches/#update-branch-protection`,
813813
);
814814
});
815815
});

0 commit comments

Comments
 (0)