Skip to content

Commit

Permalink
fix(axios-instance): prevent 'Uncaught TypeError: instance.defaults.h…
Browse files Browse the repository at this point in the history
…eaders is undefined' error

supporting redaxios
  • Loading branch information
leomp12 committed Mar 10, 2021
1 parent 5831fea commit a1b1605
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const instance = axios.create({
})
// always JSON for request with body data
;['post', 'patch', 'put'].forEach(method => {
if (!instance.defaults.headers) {
instance.defaults.headers = {}
}
instance.defaults.headers[method]['Content-Type'] = 'application/json'
})

Expand Down

0 comments on commit a1b1605

Please sign in to comment.