Skip to content

Instantly share code, notes, and snippets.

@Godofbrowser
Last active November 11, 2019 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Godofbrowser/3acf38021933d912efe753a1733b5996 to your computer and use it in GitHub Desktop.
Save Godofbrowser/3acf38021933d912efe753a1733b5996 to your computer and use it in GitHub Desktop.
This gist is part of an article and may not covey the actual message on it's own. Link to article: https://medium.com/@ejjay/a-short-ajax-story-on-error-handlers-8baeeccbc062
import axios from 'axios';
import {notifier} from './util';
axios.interceptors.response.use(undefined, function (error) {
const statusCode = error.response ? error.response.status : null;
if (statusCode === 404) {
notifier.error('The requested resource does not exist or has been deleted')
}
if (statusCode === 401) {
notifier.error('Please login to access this resource')
}
return Promise.reject(error);
})
// Fetch some missing information
axios.get('/api/articles/not-found').then(resp => {
// So something with article information
}).catch(error => {
// ignore since error was handled globally
})
// Fetch some missing information
axios.get('/api/users/not-found').then(resp => {
// So something with user information
}).catch(error => {
// ignore since error was handled globally
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment