Skip to content

Commit c134b7f

Browse files
committed
http axios driver: make response checker optional
1 parent f676eb9 commit c134b7f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/drivers/http/axios.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { deepMerge } from '../../utils'
44
export const AxiosHttpDriverDefaultOptions = {
55
tokenType: 'Bearer',
66
apiBaseURL: '/',
7-
authorizationHeader: 'Authorization'
7+
authorizationHeader: 'Authorization',
8+
responseChecker (response) {
9+
return true
10+
}
811
}
912

1013
export class AxiosHttpDriver {
1114
constructor (options) {
1215
this.options = deepMerge(AxiosHttpDriverDefaultOptions, options)
1316
}
1417

15-
// Send request helpers
1618
async sendRequest (method, url, data = {}, config = {}) {
1719
return axios.request({
1820
method,
@@ -22,7 +24,7 @@ export class AxiosHttpDriver {
2224
...config
2325
})
2426
.then(response => {
25-
if (!response || !response.data || !response.data.status || response.data.status !== 'success') {
27+
if (this.options.responseChecker && !this.options.responseChecker(response)) {
2628
throw new Error('API request failed')
2729
}
2830

0 commit comments

Comments
 (0)