Skip to content

Commit

Permalink
fix(observatory): better glean error keys (#11597)
Browse files Browse the repository at this point in the history
  • Loading branch information
argl authored Aug 6, 2024
1 parent 804d452 commit 985a416
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/src/observatory/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function ObservatoryLanding() {
useEffect(() => {
if (error && !isMutating) {
gleanClick(
`${OBSERVATORY}: error -> ${ERROR_MAP[error.name] || error.message}`
`${OBSERVATORY}: error -> ${ERROR_MAP[error.name] || error.name || error.message}`
);
}
}, [error, isMutating, gleanClick]);
Expand Down
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 985a416

Please sign in to comment.