From 55dd2fa7d942f6f1534a0418f5e345421fbc7ce2 Mon Sep 17 00:00:00 2001 From: bonomat Date: Tue, 23 Nov 2021 13:26:26 +1100 Subject: [PATCH] Throw HTTP Error so that `userErrorToast` works --- taker-frontend/src/App.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/taker-frontend/src/App.tsx b/taker-frontend/src/App.tsx index c7d3a25..6b856b3 100644 --- a/taker-frontend/src/App.tsx +++ b/taker-frontend/src/App.tsx @@ -41,7 +41,8 @@ async function getMargin(payload: MarginRequestPayload): Promise let res = await fetch(`/api/calculate/margin`, { method: "POST", body: JSON.stringify(payload) }); if (!res.status.toString().startsWith("2")) { - throw new Error("failed to create new CFD order request: " + res.status + ", " + res.statusText); + const resp = await res.json(); + throw new HttpError(resp); } return res.json(); @@ -50,8 +51,8 @@ async function getMargin(payload: MarginRequestPayload): Promise async function postCfdOrderRequest(payload: CfdOrderRequestPayload) { let res = await fetch(`/api/cfd/order`, { method: "POST", body: JSON.stringify(payload) }); if (!res.status.toString().startsWith("2")) { - console.log(`Error${JSON.stringify(res)}`); - throw new Error("failed to create new CFD order request: " + res.status + ", " + res.statusText); + const resp = await res.json(); + throw new HttpError(resp); } }