Open
Description
Hello
Errors 500 are not propagated by the client to be catched by the ui
private fetch = (input: globalThis.RequestInfo, init?: RequestInit): Promise<any> => {
const key = input.toString();
return new Promise<any>(async (resolve, reject) => {
if (this.inflight[key]) {
this.inflight[key].push({ resolve, reject });
return;
}
this.inflight[key] = [{ resolve, reject }];
try {
const res = await fetch(input, init);
const inflight = this.inflight[key];
if (res.status === 200) {
const json = await res.json();
delete this.inflight[key];
setTimeout(() => {
inflight.forEach((cb) => cb.resolve(json));
}, 0);
}
if (res.status >= 401 && res.status <= 499) {
this.csrfToken = undefined;
delete this.inflight[key];
inflight.forEach((cb) => cb.reject('unauthorized'));
this.fetchUser();
}
} catch (e: any) {
const inflight = this.inflight[key];
delete this.inflight[key];
inflight.forEach((cb) => cb.reject(e));
}
});
};
if we have a >= 500 error, it is not propagated (for exp when an api goes down) I have shut down my graphql api on purpoose, but the error is not catched
try {
await createMessage({
input: { ...values },
});
form.reset();
} catch (err) {
console.log({ err });
}
The request failed as expected but no error was propagated due to the client implementation
I propose to throw an error if res. status is 500 + or to return an error response
Thnx
Metadata
Metadata
Assignees
Labels
No labels