Skip to content

Commit

Permalink
Merge branch 'MP-1397-obs-glean-error-handling' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
argl committed Aug 5, 2024
2 parents eb67261 + 4c57fda commit 1a37897
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions client/src/observatory/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,23 @@ export function useResult(host?: string) {

export async function handleJsonResponse<T>(res: Response): Promise<T> {
if (!res.ok && res.status !== 429) {
// Example error payload we get from the Observatory API:
// {
// "statusCode": 422,
// "error": "invalid-hostname-lookup",
// "message": "unknownhostmcunknownhostface.mozilla.org cannot be resolved"
// }
// We convey the `message` to the user and use the `error` field for glean telemetry.
let message = `${res.status}: ${res.statusText}`;
let errName = "Error";
try {
const data = await res.json();
if (data.error) {
message = data.message;
}
errName = data.error || errName;
message = data.message || message;
} finally {
throw Error(message);
const err = new Error(message);
err.name = errName;
throw err;
}
}
return await res.json();
Expand Down

0 comments on commit 1a37897

Please sign in to comment.