From 1fc5f15aaa5b9aee2aebe4f46353ed6e8f072c40 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Mon, 18 Feb 2019 19:36:24 +0300 Subject: [PATCH] Check if error has response --- client/src/api/Api.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/src/api/Api.js b/client/src/api/Api.js index e77b083c..688049c9 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -15,7 +15,11 @@ export default class Api { return response.data; } catch (error) { console.error(error); - throw new Error(`${this.baseUrl}/${path} | ${error.response.data} | ${error.response.status}`); + const errorPath = `${this.baseUrl}/${path}`; + if (error.response) { + throw new Error(`${errorPath} | ${error.response.data} | ${error.response.status}`); + } + throw new Error(`${errorPath} | ${error}`); } }