Comments (13)
@pi0 you're right. I restarted and still fixed. Sorry, should have rebuilt from scratch after upgrading.
from legacy-modules.
I was able to confirm that the proper response was returned when I bypass the proxy
from legacy-modules.
Hey. Are you testing with latest master version? What if you manually remove errorhandler's logic?
from legacy-modules.
Please upgrade to @nuxtjs/axios
:2.3.0 and compare result :)
from legacy-modules.
Also i think this would be correct usage:
let user = (await app.$axios.get('/user/me')).data
from legacy-modules.
awesome. that did fix the issue!
However,
the caught error is now,
TypeError: Cannot read property '500' of undefined
at Object.errorHandler (server-bundle.js:1479:22)
at process._tickCallback (internal/process/next_tick.js:109:7)
from legacy-modules.
Would you please send a copy of generated .nuxt/axios.plugin.*.js
?
from legacy-modules.
import Axios from 'axios'
import Vue from 'vue'
const axiosPlugin = {
install() {
if(Vue.__nuxt_axios_installed__) {
return
}
Vue.__nuxt_axios_installed__ = true
if (!Vue.prototype.hasOwnProperty('$axios')) {
Object.defineProperty(Vue.prototype, '$axios', {
get () {
return this.$root.$options.$axios
}
})
}
// Vue Component Mixins
Vue.mixin({
methods: {
// opts
$request (opts) {
return this.$axios.request(opts);
},
// url, opts
$get (url, opts) {
return this.$axios.get(url, opts);
},
$delete (url, opts) {
return this.$axios.delete(url, opts);
},
$head (url, opts) {
return this.$axios.head(url, opts);
},
// url, data, opts
$post (url, data, opts) {
return this.$axios.post(url, data, opts);
},
$put (url, data, opts) {
return this.$axios.put(url, data, opts);
},
$patch (url, data, opts) {
return this.$axios.patch(url, data, opts);
}
}
})
}
}
Vue.use(axiosPlugin)
// Sets a common header
function setHeader (name, value, scopes = 'common') {
if(!Array.isArray(scopes)) {
scopes = [scopes]
}
scopes.forEach(scope => {
if (!value) {
delete this.defaults.headers[scope][name];
return
}
this.defaults.headers[scope][name] = value
})
}
// Set requests token
function setToken (token, type, scopes = 'common') {
const value = !token ? null : (type ? type + ' ' : '') + token
this.setHeader('Authorization', value, scopes)
}
const redirectError = {}
// Set appreciate `statusCode` and `message` to error instance
function errorHandler(error) {
if (error.response) {
// Error from backend (non 2xx status code)
// ...Auto redirect on special status codes
if (redirectError[error.response.status]) {
this.redirect(redirectError[error.response.status])
}
error.statusCode = error.statusCode || parseInt(error.response.status) || 500
error.message = error.message || error.response.statusText || (error.statusCode + ' (Internal Server Error)')
} else if (error.request) {
// Error while making request
error.statusCode = error.statusCode || 500
error.message = error.message || 'request error'
} else {
// Something happened in setting up the request that triggered an Error
error.statusCode = 500
error.message = error.message || 'axios error'
}
return Promise.reject(error)
}
// Setup BaseURL
const baseURL = process.browser
? (process.env.API_URL_BROWSER || '/api')
: (process.env.API_URL || 'http://667837fe8085:3000/api')
export default (ctx) => {
const { app, store, req } = ctx
// Default headers
const defaultHeaders = (req && req.headers) ? Object.assign({}, req.headers) : {}
delete defaultHeaders.host
// Create new axios instance
const axios = Axios.create({
baseURL,
defaultHeaders,
})
// Send credentials only to relative and API Backend requests
axios.interceptors.request.use(config => {
if (config.withCredentials === undefined) {
if (!/^https?:\/\//i.test(config.url) || config.url.indexOf(baseURL) === 0) {
config.withCredentials = true
}
}
return config
});
// Error handler
axios.interceptors.response.use(undefined, errorHandler.bind(ctx));
// Make accessible using *.$axios
app.$axios = axios
ctx.$axios = axios
if (store) {
store.$axios = axios
}
// Token helper for authentication
axios.setToken = setToken.bind(axios)
axios.setHeader = setHeader.bind(axios)
}
from legacy-modules.
I tought problem would be with new redirectError
feature. But it is defined too 😕 Does disable this line fixes problem?
if (redirectError[error.response.status]) {
this.redirect(redirectError[error.response.status])
}
from legacy-modules.
where should i put this?
from legacy-modules.
This line is in .nuxt/axios
file you have submitted. Sorry for inconveniences. Trying to guess problem.
from legacy-modules.
i think that fixed it. now i see the response object.
from legacy-modules.
@uptownhr Sorry bothering, but would you please restart dev server if error exists? I can't reproduce it.
from legacy-modules.
Related Issues (20)
- markdownit v1.2.8 typo: Object.asign is not a function HOT 1
- @nuxtjs/toast - How to pass options to globally configured toast module HOT 3
- Module in a separate chunk ? HOT 1
- Hot Reload doesn't work
- Nuxt Runtime Config
- RTL support
- Add ignoreRoutes option
- Is it dead? HOT 3
- Sorting by stars HOT 1
- Extract markdownit module HOT 3
- Extract yandex-metrika module HOT 3
- Extract component-cache module
- Extract bulma-module HOT 5
- @nuxtjs/browserconfig - Incorrect XML markup?
- Discussion about last modules HOT 3
- toast ssr problem HOT 3
- @nuxtjs/yandex-metrika | Counter not found, but data is being transferred
- @nuxtjs/toast => Cannot read property 'show' of undefined HOT 2
- Dependency Dashboard
- P
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from legacy-modules.