chore(eslint): fix getJSON reponse type

This commit is contained in:
Paul Chavard 2022-02-23 13:08:02 +01:00 committed by Pierre de La Morinerie
parent beafa21796
commit a914950982

View file

@ -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);
});
}