Skip to content

Instantly share code, notes, and snippets.

@Godofbrowser
Last active November 11, 2019 22:04
Show Gist options
  • Save Godofbrowser/76a3969f06736aa38b8a9c0902debb7e to your computer and use it in GitHub Desktop.
Save Godofbrowser/76a3969f06736aa38b8a9c0902debb7e to your computer and use it in GitHub Desktop.

Revisions

  1. Godofbrowser revised this gist Nov 11, 2019. No changes.
  2. Godofbrowser revised this gist Nov 11, 2019. No changes.
  3. Godofbrowser revised this gist Nov 11, 2019. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions a-short-ajax-error-story-1-of-4.js
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,16 @@ import {notifier} from './util';

    // Fetch some missing information
    axios.get('/api/articles/not-found').then(resp => {
    // Do something with the response data
    // So something with article information
    }).catch(error => {
    // 404 - Not found error
    if (error.status === 404) {
    const statusCode = error.response ? error.response.status : null;

    // 404 - not found
    if (statusCode === 404) {
    notifier.error('The requested article does not exist or has been deleted')
    }

    if (error.status === 401) {
    if (statusCode === 401) {
    notifier.error('Please login to view this article')
    }
    })
    @@ -21,11 +23,13 @@ axios.get('/api/articles/not-found').then(resp => {
    axios.get('/api/users/not-found').then(resp => {
    // So something with user information
    }).catch(error => {
    if (error.status === 404) {
    const statusCode = error.response ? error.response.status : null;

    if (statusCode === 404) {
    notifier.error('The requested user does not exist or has been deleted')
    }

    if (error.status === 401) {
    if (statusCode === 401) {
    notifier.error('Please login to view this user')
    }
    })
  4. Godofbrowser revised this gist Nov 10, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions a-short-ajax-error-story-1-of-4.js
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@ import {notifier} from './util';

    // Fetch some missing information
    axios.get('/api/articles/not-found').then(resp => {
    // So something with product information
    // Do something with the response data
    }).catch(error => {
    // 404 - Product not found error
    // 404 - Not found error
    if (error.status === 404) {
    notifier.error('The requested article does not exist or has been deleted')
    }
  5. Godofbrowser revised this gist Nov 10, 2019. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion a-short-ajax-error-story-1-of-4.js
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,24 @@ axios.get('/api/articles/not-found').then(resp => {
    }).catch(error => {
    // 404 - Product not found error
    if (error.status === 404) {
    notifier.error('The requested article does not exist or it has been deleted')
    notifier.error('The requested article does not exist or has been deleted')
    }

    if (error.status === 401) {
    notifier.error('Please login to view this article')
    }
    })


    // Fetch some missing information
    axios.get('/api/users/not-found').then(resp => {
    // So something with user information
    }).catch(error => {
    if (error.status === 404) {
    notifier.error('The requested user does not exist or has been deleted')
    }

    if (error.status === 401) {
    notifier.error('Please login to view this user')
    }
    })
  6. Godofbrowser revised this gist Nov 10, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion a-short-ajax-error-story-1-of-4.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ axios.get('/api/articles/not-found').then(resp => {
    }).catch(error => {
    // 404 - Product not found error
    if (error.status === 404) {
    notifier.error('The requested article does not exists or it has been deleted')
    notifier.error('The requested article does not exist or it has been deleted')
    }

    if (error.status === 401) {
  7. Godofbrowser created this gist Nov 10, 2019.
    17 changes: 17 additions & 0 deletions a-short-ajax-error-story-1-of-4.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    import axios from 'axios';
    import {notifier} from './util';


    // Fetch some missing information
    axios.get('/api/articles/not-found').then(resp => {
    // So something with product information
    }).catch(error => {
    // 404 - Product not found error
    if (error.status === 404) {
    notifier.error('The requested article does not exists or it has been deleted')
    }

    if (error.status === 401) {
    notifier.error('Please login to view this article')
    }
    })