diff --git a/src/fetch-wrapper.ts b/src/fetch-wrapper.ts index 5c1caf83b..bf65ba426 100644 --- a/src/fetch-wrapper.ts +++ b/src/fetch-wrapper.ts @@ -176,13 +176,22 @@ async function getResponseData(response: Response) { function toErrorMessage(data: any) { if (typeof data === "string") return data; + let 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 diff --git a/test/request.test.ts b/test/request.test.ts index e5456c559..294480e0b 100644 --- a/test/request.test.ts +++ b/test/request.test.ts @@ -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`, ); }); });