about summary refs log tree commit diff
path: root/app/javascript/mastodon/middleware
diff options
context:
space:
mode:
authorunarist <m.unarist@gmail.com>2018-04-02 21:51:02 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-04-02 14:51:02 +0200
commit2c51bc0ca5a4c3a4bb140b4b40dabdda859ebb94 (patch)
treedfc6ec5791ab17992f6940da330b3b7193f80ec4 /app/javascript/mastodon/middleware
parente7a17167015dca6864f31152c47334c3b3a857a2 (diff)
Add missing rejection handling for Promises (#7008)
* Add eslint-plugin-promise to detect uncaught rejections

* Move alert generation for errors to actions/alert

* Add missing rejection handling for Promises

* Use catch() instead of onReject on then()

Then it will catches rejection from onFulfilled. This detection can be
disabled by `allowThen` option, though.
Diffstat (limited to 'app/javascript/mastodon/middleware')
-rw-r--r--app/javascript/mastodon/middleware/errors.js24
1 files changed, 2 insertions, 22 deletions
diff --git a/app/javascript/mastodon/middleware/errors.js b/app/javascript/mastodon/middleware/errors.js
index 72e5631e6..3cebb42e0 100644
--- a/app/javascript/mastodon/middleware/errors.js
+++ b/app/javascript/mastodon/middleware/errors.js
@@ -1,34 +1,14 @@
-import { defineMessages } from 'react-intl';
-import { showAlert } from '../actions/alerts';
+import { showAlertForError } from '../actions/alerts';
 
 const defaultFailSuffix = 'FAIL';
 
-const messages = defineMessages({
-  unexpectedTitle: { id: 'alert.unexpected.title', defaultMessage: 'Oops!' },
-  unexpectedMessage: { id: 'alert.unexpected.message', defaultMessage: 'An unexpected error occurred.' },
-});
-
 export default function errorsMiddleware() {
   return ({ dispatch }) => next => action => {
     if (action.type && !action.skipAlert) {
       const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
 
       if (action.type.match(isFail)) {
-        if (action.error.response) {
-          const { data, status, statusText } = action.error.response;
-
-          let message = statusText;
-          let title   = `${status}`;
-
-          if (data.error) {
-            message = data.error;
-          }
-
-          dispatch(showAlert(title, message));
-        } else {
-          console.error(action.error);
-          dispatch(showAlert(messages.unexpectedTitle, messages.unexpectedMessage));
-        }
+        dispatch(showAlertForError(action.error));
       }
     }