From 3d4328e59f3d52cc02a4783f35ccd97bb7147c36 Mon Sep 17 00:00:00 2001 From: dev-chiefworks Date: Wed, 11 Jan 2023 21:05:52 -0500 Subject: [PATCH] Error catch --- src/vendors/service/siteService.js | 50 +++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/vendors/service/siteService.js b/src/vendors/service/siteService.js index 801d12c..2381c0d 100644 --- a/src/vendors/service/siteService.js +++ b/src/vendors/service/siteService.js @@ -12,22 +12,48 @@ class SiteService { getAuxEnd(uri, reqData) { const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri; - Axios.get(endPoint).then((response) => { - console.log(response); - res = response; - console.log("~~~~~~~ Toks2 GET ~~~~~~~~"); - return response; - }); + Axios.get(endPoint) + .then((response) => { + console.log(response); + res = response; + console.log("~~~~~~~ Toks2 GET ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log(error.response.status); + } else if (error.request) { + //response not received though the request was sent + console.log(error.request); + } else { + //an error occurred when setting up the request + console.log(error.message); + } + }); } getAuxEnd(uri, reqData) { const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri; - Axios.post(endPoint).then((response) => { - console.log(response); - res = response; - console.log("~~~~~~~ Toks2 POST ~~~~~~~~"); - return response; - }); + Axios.post(endPoint) + .then((response) => { + console.log(response); + res = response; + console.log("~~~~~~~ Toks2 POST ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log(error.response.status); + } else if (error.request) { + //response not received though the request was sent + console.log(error.request); + } else { + //an error occurred when setting up the request + console.log(error.message); + } + }); } }