Skip to content

Commit

Permalink
Report documentation with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoref committed Feb 9, 2024
1 parent 3d22c38 commit d5da66e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,22 @@ async function getResponseData(response: Response) {
function toErrorMessage(data: any) {
if (typeof data === "string") return data;

var suffix: string;

// istanbul ignore else - just in case
if ("documentation_url" in data) {
suffix = ` - ${data.documentation_url}`;
} else {
suffix = "";
}

// istanbul ignore else - just in case
if ("message" in data) {
if (Array.isArray(data.errors)) {
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}`;
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`;
}

return data.message;
return `${data.message}${suffix}`;
}

// istanbul ignore next - just in case
Expand Down
2 changes: 1 addition & 1 deletion test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
.catch((error) => {
expect(error).toHaveProperty(
"message",
`Validation failed: "Only organization repositories can have users and team restrictions", {"resource":"Search","field":"q","code":"invalid"}`,
`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`,
);
});
});
Expand Down

0 comments on commit d5da66e

Please sign in to comment.