From c829e1e983f8089ca4836c3b0c948471eda2b4e0 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 9 Mar 2021 22:15:29 +0100 Subject: [PATCH] todo: fix error response parsing and set NotFoundError name Signed-off-by: Patrik Oldsberg --- plugins/todo/src/api/TodoClient.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/todo/src/api/TodoClient.ts b/plugins/todo/src/api/TodoClient.ts index fb0c03bac6..b8caee3ee9 100644 --- a/plugins/todo/src/api/TodoClient.ts +++ b/plugins/todo/src/api/TodoClient.ts @@ -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;