Files
app
assets
fonts
images
javascripts
components
actions
components
containers
features
locales
middleware
errors.jsx
loading_bar.jsx
sounds.jsx
reducers
selectors
store
.gitkeep
api.jsx
emoji.jsx
is_mobile.jsx
link_header.jsx
rtl.jsx
stream.jsx
uuid.jsx
application.js
application_public.js
components.js
extras.jsx
stylesheets
controllers
helpers
lib
mailers
models
presenters
services
validators
views
workers
bin
config
db
docs
lib
log
public
spec
storybook
streaming
vendor
.babelrc
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.json
.gitignore
.nvmrc
.rspec
.rubocop.yml
.ruby-version
.slugignore
.travis.yml
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
ISSUE_TEMPLATE.md
LICENSE
Procfile
README.md
Rakefile
Vagrantfile
app.json
config.ru
docker-compose.yml
package.json
scalingo.json
yarn.lock
hometown/app/assets/javascripts/components/middleware/errors.jsx
Zac Anger f4045ba3d9 Add eslint-plugin-jsx-a11y ()
* Add eslint-plugin-jsx-a11y.

* Fix npm script.

* Adjust npm scripts so test also runs lint.

* Fix existing lint errors.

* Don't break on a11y issues.

* Add role and tabIndex.

* Add vim and Mac files to .gitignore and .dockerignore.

* Handle htmlFor (partially), a that's actually a button.

* Fix missing tabIndex.

* Add cursor:pointer to load-more

* Revert change to load_more.

* Fixes based on review.

* Update yarn.lock.

* Don't try to install fsevents on Linux (hides warning noise).
2017-04-15 13:27:27 +02:00

34 lines
956 B
JavaScript

import { showAlert } from '../actions/alerts';
const defaultSuccessSuffix = 'SUCCESS';
const defaultFailSuffix = 'FAIL';
export default function errorsMiddleware() {
return ({ dispatch }) => next => action => {
if (action.type && !action.skipAlert) {
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
const isSuccess = new RegExp(`${defaultSuccessSuffix}$`, '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); // eslint-disable-line no-console
dispatch(showAlert('Oops!', 'An unexpected error occurred.'));
}
}
}
return next(action);
};
};