Skip to content

Commit c1bd54c

Browse files
committed
handle error descriptions from quarto-pub
1 parent 4e2f882 commit c1bd54c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/publish/quarto-pub/api/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ export class QuartoPubClient {
192192

193193
// If the response was not OK, throw an ApiError.
194194
if (!response.ok) {
195-
throw new ApiError(response.status, response.statusText);
195+
const description = await descriptionFromErrorResponse(response);
196+
throw new ApiError(response.status, description || response.statusText);
196197
}
197198

198199
// Return the result.
@@ -266,3 +267,17 @@ export class QuartoPubClient {
266267
// Creates a URL.
267268
private createURL = (path: string) => `${this.baseURL_}/${path}`;
268269
}
270+
271+
async function descriptionFromErrorResponse(response: Response) {
272+
// if there is a body, see if its a quarto pub error w/ description
273+
if (response.body) {
274+
try {
275+
const result = await response.json();
276+
if (typeof (result.description) === "string") {
277+
return result.description;
278+
}
279+
} catch {
280+
//
281+
}
282+
}
283+
}

0 commit comments

Comments
 (0)