aboutsummaryrefslogtreecommitdiff
path: root/src/reducers/error.reducer.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/reducers/error.reducer.js')
-rw-r--r--src/reducers/error.reducer.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/reducers/error.reducer.js b/src/reducers/error.reducer.js
new file mode 100644
index 0000000..83d1128
--- /dev/null
+++ b/src/reducers/error.reducer.js
@@ -0,0 +1,18 @@
+export default function ErrorReducer(state = {}, action) {
+ const { type, error } = action;
+ const matches = /(.*)_(REQUEST|FAILED|ERROR)/.exec(
+ type
+ );
+ if (!matches) return state;
+ const [, requestName, requestState] = matches;
+ return {
+ errorMessage:
+ requestState === "FAILED" || requestState === "ERROR"
+ ? error
+ ? error
+ : ""
+ : "",
+ [requestName]: requestState === "FAILED" || requestState === "ERROR" ? true: false
+ };
+ }
+ \ No newline at end of file