lundi 5 juillet 2021

If we get some error on API (4xx or 5xx), we should be showing something on the screen

How to handle such errors and show message on the screen?

The code is:

import Route from '@ember/routing/route';
import ENV from 'website-my/config/environment';

const API_BASE_URL = ENV.BASE_API_URL;

export default class TasksRoute extends Route {
  model = async () => {
    const response = await fetch(`${API_BASE_URL}/tasks/self`, {
      credentials: 'include',
    });
    const allTasks = await response.json();

    return allTasks;
  };
}

I want to add error handling in this, How to do that?




Aucun commentaire:

Enregistrer un commentaire