todo: fix error response parsing and set NotFoundError name

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-03-09 22:15:29 +01:00
parent 117286b313
commit c829e1e983
+4 -1
View File
@@ -69,7 +69,7 @@ export class TodoClient implements TodoApi {
error.status = res.status;
try {
const json = await res.json();
const json = await res.clone().json();
if (typeof json?.error?.message !== 'string') {
throw new Error('invalid error');
}
@@ -84,6 +84,9 @@ export class TodoClient implements TodoApi {
} catch {
error.message = `Failed to ${action}, status ${res.status}`;
}
if (res.status === 404) {
error.name = 'NotFoundError';
}
}
throw error;