I recently developed a server-side plugin and encountered the following error:
context.app.handleServerError is not a function
// hanlde-server-error.js
export default ({ app }, inject) => {
app.handleServerError = (method, error, data) => {
const message = `An error occurred 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' })
}
},
Is it safe to assume that asyncData is executed server-side? As per the documentation, this function is supposed to be accessible via the context.