Thứ Năm, 13 tháng 6, 2019

CustomNetworkError dart - call rest api

class CustomNetworkError {
  static String getErrorMessage(int code) {
    switch (code) {
      case 500:
        return 'server issue';
      case 401:
        return 'token auth missing or incorrect or no such credentials any more';
      case 404:
        return 'missing resource';
      case 403:
        return 'authenticated but insufficient permission for action';
      case 405:
        return 'method not allowed — when you try to access a POST with a GET etc.';
      case 400:
        return 'bad request — for example if you don’t submit username and password fields to login';
      default:
        return 'unknown error';
    }
  }
}