diff --git a/app/javascript/shared/utils.ts b/app/javascript/shared/utils.ts index 02a88ee87..0882f088c 100644 --- a/app/javascript/shared/utils.ts +++ b/app/javascript/shared/utils.ts @@ -88,6 +88,15 @@ export function ajax(options: Rails.AjaxOptions) { }); } +class ResponseError extends Error { + response: Response; + + constructor(response: Response) { + super(String(response.statusText || response.status)); + this.response = response; + } +} + export function getJSON(url: string, data: unknown, method = 'GET') { const { query, ...options } = fetchOptions(data, method); @@ -98,9 +107,7 @@ export function getJSON(url: string, data: unknown, method = 'GET') { } return response.json(); } - const error = new Error(String(response.statusText || response.status)); - (error as any).response = response; - throw error; + throw new ResponseError(response); }); }