Merge pull request #18 from TouchInstinct/feature/add_request_error

Add request error
This commit is contained in:
grigoriishveps 2022-02-02 16:34:28 +03:00 committed by GitHub
commit df158a995a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -1,4 +1,11 @@
export interface ApiError {
export class ApiError extends Error {
errorCode: number
errorMessage: Nullable<string>
constructor(error: any) {
super(error.message)
this.errorCode = error?.response?.data?.errorCode ?? -1
this.errorMessage = error?.response?.data?.errorMessage
}
}

View File

@ -1,6 +1,7 @@
import axios, { AxiosRequestConfig } from 'axios'
import logger from 'lib/logger'
import { ApiError } from './error'
const retrieve = async (
props: AxiosRequestConfig,
@ -15,7 +16,7 @@ const retrieve = async (
return retrieve(props, true)
}
throw new Error(err)
throw new ApiError(err)
}
}