-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AxiosException class #2014
Merged
jasonsaayman
merged 2 commits into
axios:release/1.0.0-beta.1
from
ruscon:feature/axios-exception
Jul 1, 2020
Merged
Add AxiosException class #2014
jasonsaayman
merged 2 commits into
axios:release/1.0.0-beta.1
from
ruscon:feature/axios-exception
Jul 1, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruscon
force-pushed
the
feature/axios-exception
branch
from
February 24, 2019 14:38
895a352
to
bdc85cd
Compare
ruscon
force-pushed
the
feature/axios-exception
branch
from
February 24, 2019 14:43
bdc85cd
to
e8ddb60
Compare
Does anyone know if this is going to move forward ? It would be really nice to be able to do a
... check in typesript |
For now, we use this: import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, default as Axios } from 'axios';
export class AxiosException<T = any> extends Error implements AxiosError {
config: AxiosRequestConfig;
code?: string;
request?: any;
response?: AxiosResponse<T>;
isAxiosError: boolean;
constructor(error: Partial<AxiosError>) {
const responseMessage: string = error.response && error.response.data ? `Response: ${JSON.stringify(error.response.data)}` : '';
const errorMessage: string = responseMessage ? `${error.message} ${responseMessage}` : error.message || '';
super(errorMessage);
Object.assign(this, error);
this.message = errorMessage;
this.name = error.constructor.name;
this.code = error.code;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, AxiosException);
}
}
}
export function createAxiosInstance(config: AxiosRequestConfig = {}): AxiosInstance {
Axios.defaults.timeout = 15000;
const axios: AxiosInstance = Axios.create(config);
// Convert axios error object to AxiosException class
axios.interceptors.response.use(
(response: AxiosResponse) => {
return response;
},
async (error: any) => {
return Promise.reject(new AxiosException(error));
},
);
return axios;
} |
IvanStoilov
pushed a commit
to IvanStoilov/axios
that referenced
this pull request
Nov 25, 2020
Co-authored-by: Coroliov Oleg <coroliov.o@goparrot.ai> Co-authored-by: Jay <jasonsaayman@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BC?: no
#2013