mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-25 00:11:36 +01:00
Merge branch 'non-json-payload' into 'dev'
Filter non-JSON payload See merge request turris/reforis/foris-js!13
This commit is contained in:
commit
0af56ec84c
2
Makefile
2
Makefile
|
@ -28,7 +28,7 @@ install-js: package.json
|
||||||
npm install --save-dev
|
npm install --save-dev
|
||||||
|
|
||||||
watch-js:
|
watch-js:
|
||||||
npm run watch
|
npm run build:watch
|
||||||
build-js:
|
build-js:
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "0.1.0-beta.6",
|
"version": "0.1.0-beta.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "foris",
|
"name": "foris",
|
||||||
"version": "0.1.0-beta.6",
|
"version": "0.1.0-beta.7",
|
||||||
"description": "Set of components and utils for Foris and its plugins.",
|
"description": "Set of components and utils for Foris and its plugins.",
|
||||||
"author": "CZ.NIC, z.s.p.o.",
|
"author": "CZ.NIC, z.s.p.o.",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useReducer, useCallback } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
API_ACTIONS, TIMEOUT, HEADERS, APIReducer,
|
API_ACTIONS, TIMEOUT, HEADERS, APIReducer, getErrorMessage,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
export function useAPIDelete(url) {
|
export function useAPIDelete(url) {
|
||||||
|
@ -31,7 +31,7 @@ export function useAPIDelete(url) {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: API_ACTIONS.FAILURE,
|
type: API_ACTIONS.FAILURE,
|
||||||
payload: error.response.data,
|
payload: getErrorMessage(error),
|
||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useReducer } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
API_ACTIONS, TIMEOUT, HEADERS, APIReducer,
|
API_ACTIONS, TIMEOUT, HEADERS, APIReducer, getErrorMessage,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
export function useAPIPatch(url) {
|
export function useAPIPatch(url) {
|
||||||
|
@ -31,7 +31,7 @@ export function useAPIPatch(url) {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: API_ACTIONS.FAILURE,
|
type: API_ACTIONS.FAILURE,
|
||||||
payload: error.response.data,
|
payload: getErrorMessage(error),
|
||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useReducer } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
API_ACTIONS, TIMEOUT, HEADERS, APIReducer,
|
API_ACTIONS, TIMEOUT, HEADERS, APIReducer, getErrorMessage,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
|
|
||||||
export function useAPIPost(url) {
|
export function useAPIPost(url) {
|
||||||
|
@ -29,14 +29,10 @@ export function useAPIPost(url) {
|
||||||
});
|
});
|
||||||
dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data });
|
dispatch({ type: API_ACTIONS.SUCCESS, payload: result.data });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let payload = "An unknown error occurred";
|
|
||||||
if (error.response.headers["content-type"] === "application/json") {
|
|
||||||
payload = error.response.data;
|
|
||||||
}
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: API_ACTIONS.FAILURE,
|
type: API_ACTIONS.FAILURE,
|
||||||
|
payload: getErrorMessage(error),
|
||||||
status: error.response.status,
|
status: error.response.status,
|
||||||
payload,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,3 +67,11 @@ export function APIReducer(state, action) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getErrorMessage(error) {
|
||||||
|
let payload = "An unknown error occurred";
|
||||||
|
if (error.response.headers["content-type"] === "application/json") {
|
||||||
|
payload = error.response.data;
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user