The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

32 lignes
829 B

  1. import { showAlert } from '../actions/alerts';
  2. const defaultFailSuffix = 'FAIL';
  3. export default function errorsMiddleware() {
  4. return ({ dispatch }) => next => action => {
  5. if (action.type) {
  6. const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
  7. if (action.type.match(isFail)) {
  8. if (action.error.response) {
  9. const { data, status, statusText } = action.error.response;
  10. let message = statusText;
  11. let title = `${status}`;
  12. if (data.error) {
  13. message = data.error;
  14. }
  15. dispatch(showAlert(title, message));
  16. } else {
  17. console.error(action.error);
  18. dispatch(showAlert('Oops!', 'An unexpected error occurred. Inspect the console for more details'));
  19. }
  20. }
  21. }
  22. return next(action);
  23. };
  24. };