ApiError.ts 464 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export default class ApiError {
  public status: number;
  public statusText: string;
  public data: any;

  public static axiosError(err): ApiError {
    const apiError = new ApiError();
    if (err.response) {
      apiError.status = err.response.status;
      apiError.statusText = err.response.statusText;
      apiError.data = err.response.data;
    } else {
      apiError.status = -1;
      apiError.data = 'Unknown error';
    }
    return apiError;
  }
}