Skip to content

Commit f1e95ff

Browse files
pschmidt88pi0
authored andcommitted
feat: disable sefault error handler (#44)
* Override the default error handler Otherwise there is the possibility that they are conflicting with each other. Also added a option, where you can disable the errorHandler at all (for example if you work with the responseInterceptor) * Changed option name and added the documentation. Renamed the option to `disableDefaultErrorHandler`. Added documention for the new option.
1 parent 06f20a6 commit f1e95ff

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [requestInterceptor](#requestinterceptor)
4949
- [responseInterceptor](#responseinterceptor)
5050
- [init](#init)
51+
- [disableDefaultErrorHandler](#disabledefaulterrorhandler)
5152
- [errorHandler](#errorhandler)
5253
- [Helpers](#helpers)
5354
- [Fetch Style Requests](#fetch-style-requests)
@@ -69,7 +70,7 @@
6970
Install with npm:
7071
```bash
7172
>_ npm install @nuxtjs/axios
72-
```
73+
```
7374

7475
Install with yarn:
7576
```bash
@@ -206,7 +207,7 @@ responseInterceptor: (response, ctx) => {
206207
```
207208

208209

209-
Function for manipulating axios responses.
210+
Function for manipulating axios responses.
210211

211212
### `init`
212213
- Default: `null`
@@ -221,12 +222,20 @@ axios: {
221222
}
222223
```
223224

225+
### `disableDefaultErrorHandler`
226+
- Default: `false`
227+
228+
If you want to disable the default error handler for some reason, you can do it so
229+
by setting the option `disableDefaultErrorHandler` to true.
230+
224231
### `errorHandler`
225232
- Default: (Return promise rejection with error)
226233

227-
Function for custom global error handler.
234+
Function for custom global error handler.
228235
This example uses nuxt default error page.
229236

237+
If you define a custom error handler, the default error handler provided by this package will be overridden.
238+
230239
```js
231240
axios: {
232241
errorHandler (errorReason, { error }) {

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = function nuxtAxios (moduleOptions) {
1919
proxyHeaders: true,
2020
proxyHeadersIgnore: ['accept', 'host'],
2121
debug: false,
22+
disableDefaultErrorHandler: false,
2223
redirectError: {}
2324
}
2425

lib/plugin.template.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ export default <% if (options.init) { %>async<% } %>(ctx, inject) => {
172172
const resInter = <%= serialize(options.responseInterceptor).replace('responseInterceptor(', 'function(').replace('function function', 'function') %>
173173
axios.interceptors.response.use(config => resInter(config, ctx))
174174
<% } %>
175-
176-
// Error handler
177-
axios.interceptors.response.use(undefined, err => errorHandler(err, ctx));
178175

176+
// Error handler
179177
<% if (options.errorHandler) { %>
180178
// Custom error handler
181179
axios.interceptors.response.use(undefined, err => customErrorHandler(err, ctx))
180+
<% } else if (options.disableDefaultErrorHandler === false) { %>
181+
axios.interceptors.response.use(undefined, err => errorHandler(err, ctx));
182182
<% } %>
183183

184184
// Inject axios to the context as $axios

0 commit comments

Comments
 (0)