From 44e45499c6a17b59eb6e3ad5a27cf3cd8f5f09ec Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Mon, 30 Sep 2019 12:58:41 +0000 Subject: [PATCH] Ignore non-JSON error payload --- package-lock.json | 2 +- package.json | 2 +- src/api/post.js | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd21f47..a48372d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "0.1.0-beta.5", + "version": "0.1.0-beta.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 65c7ed1..297ecf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "0.1.0-beta.5", + "version": "0.1.0-beta.6", "description": "Set of components and utils for Foris and its plugins.", "author": "CZ.NIC, z.s.p.o.", "repository": { diff --git a/src/api/post.js b/src/api/post.js index b866f40..dc97796 100644 --- a/src/api/post.js +++ b/src/api/post.js @@ -29,10 +29,14 @@ export function useAPIPost(url) { }); dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data }); } catch (error) { + let payload = "An unknown error occurred"; + if (error.response.headers["content-type"] === "application/json") { + payload = error.response.data; + } dispatch({ type: API_ACTIONS.FAILURE, - payload: error.response.data, status: error.response.status, + payload, }); } };