Reputation: 713
I created a server side plugin and I'm getting
context.app.handleServerError is not a function
// hanlde-server-error.js
export default ({ app }, inject) => {
app.handleServerError = (method, error, data) => {
const message = `An error occured in ${method}. ${error}`
console.error(message)
Sentry.captureException(new Error(message))
}
}
// nuxt.config.js
plugins: [
{ src: '~plugins/handle-server-error', mode: 'server' },
],
// calling function
async asyncData(context) {
// await store.dispatch('fetchAccounts')
try {
await undefinedFunction()
} catch (error) {
context.app.handleServerError('asyncData', error, { user: 'bambam' })
}
},
Am I correct that asyncData makes the call server side? According to the docs this function should be available on context.
Upvotes: 0
Views: 4171
Reputation: 4779
Execute it only server side.
async asyncData(context) {
if (process.server) {
try {
await undefinedFunction()
} catch (error) {
context.app.handleServerError('asyncData', error, { user: 'bambam' })
}
}
},
Upvotes: 1