import { showMessageBarMessage } from 'containers/MessageBar/actions';

// Works with redux-api-middleware, taking action when requests fail
const apiErrorHandlingMidddlware = (store) => (next) => (action) => {
  const message = action.payload ? fetchError(action.payload) || false : false;
  if (message) {
    store.dispatch(showMessageBarMessage(message));
  }
  return next(action);
};

function fetchError(payload) {
  let response = '';

  if (payload.name === 'ApiError' || payload.name === 'SubmissionError') {
    const errorData = payload.errors ? payload.errors : payload.response;

    if (errorData.status === 403) {
      response = 'Invalid request - 403';
    } else if (errorData.status === 401) {
      response = 'Unauthorized, please try your request again - 401';
    } else if (errorData.status === 404) {
      response = 'Error reaching server - 404';
    } else if (errorData.status === 500) {
      response = errorData.message;
    }
  }

  return response;
}

export default apiErrorHandlingMidddlware;

import { showMessageBarMessage } from 'containers/MessageBar/actions';

// Works with redux-api-middleware, taking action when requests fail
const apiErrorHandlingMidddlware = (store) => (next) => (action) => {
  const message = action.payload ? fetchError(action.payload) || false : false;
  if (message) {
    store.dispatch(showMessageBarMessage(message));
  }
  return next(action);
};

function fetchError(payload) {
  let response = '';

  const errorData = payload.errors ? payload.errors : payload.response;

  if (errorData && errorData.status) {
    if (errorData.status === 403) {
      response = 'Invalid request - 403';
    } else if (errorData.status === 401) {
      response = 'Unauthorized, please try your request again - 401';
    } else if (errorData.status === 404) {
      response = 'Error reaching server - 404';
    } else if (errorData.status === 500) {
      response = errorData.message;
    }
  }

  return response;
}

export default apiErrorHandlingMidddlware;

Fix snackbar in production, where the error name was being minimized Squashed commit of the following:
Fix snackbar in production, where the error name was being minimized
Squashed commit of the following:

commit e0b1b02001d138441bb40a432b412043ab83bc62
Author: Jesse Smith <sosaucily@gmail.com>
Date:   Tue Apr 25 11:46:24 2017 +0200

    add some logging
