mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Allow custom HTTP status code error ranges (#308)
Adding support for custom HTTP status code error ranges
This commit is contained in:
committed by
Matt Zabriskie
parent
093593cbca
commit
fa9444e0ba
@@ -261,12 +261,20 @@ These are the available config options for making requests. Only the `url` is re
|
||||
|
||||
// `progress` allows handling of progress events for 'POST' and 'PUT uploads'
|
||||
// as well as 'GET' downloads
|
||||
progress: function(progressEvent) {
|
||||
progress: function (progressEvent) {
|
||||
// Do whatever you want with the native progress event
|
||||
},
|
||||
|
||||
// `maxContentLength` defines the max size of the http response content allowed
|
||||
maxContentLength: 2000
|
||||
maxContentLength: 2000,
|
||||
|
||||
// `validateStatus` defines whether to resolve or reject the promise for a given
|
||||
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
||||
// or `undefined`), the promise will be resolved; otherwise, the promise will be
|
||||
// rejected.
|
||||
validateStatus: function (status) {
|
||||
return status >= 200 && status < 300; // default
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -406,6 +414,16 @@ axios.get('/user/12345')
|
||||
});
|
||||
```
|
||||
|
||||
You can define a custom HTTP status code error range using the `validateStatus` config option.
|
||||
|
||||
```js
|
||||
axios.get('/user/12345', {
|
||||
validateStatus: function (status) {
|
||||
return status < 500; // Reject only if the status code is greater than or equal to 500
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Semver
|
||||
|
||||
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
|
||||
|
||||
Reference in New Issue
Block a user