i am fetching data from a sever and sometime the request take so long and the sever responds with a 408 status so my code looks like this
export class ResponseError extends Error {
public response: Response;
constructor(response: Response) {
super(response.statusText);
this.response = response;
}
function parseJSON(response: Response) {
if (response.status === 204 || response.status === 205) {
return null;
}
return response.json();
}
function checkStatus(response: Response) {
if (response.status >= 200 && response.status < 300) {
return response;
}
const error = new ResponseError(response);
error.response = response;
throw error;
}
export async function request(
url: string,
options?: RequestInit,
): Promise<{} | { err: ResponseError }> {
const fetchResponse = await fetch(url, options);
const response = checkStatus(fetchResponse);
return parseJSON(response);
}
how can i retry the request if the response status code 408 is received