todo: fix error response parsing and set NotFoundError name
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user