adonis-apollo-server
adonis-apollo-server copied to clipboard
Error handling
It appears that error handling is broken. The HTTP status is returned in statusCode
attribute, rather than status
for errors coming from GraphQL middleware.
https://github.com/ammezie/adonis-apollo-server/blob/d28426c23c48e2916a5b66997a0a30ab111727c9/src/ApolloServer/index.js#L38
But, on top of that, I am questioning the need to handle errors there at all. Why not just let the error bubble up and be dealt with by an exceptions handler (app/Exceptions/Handler.js
), which does need to be user-defined, but maybe add instructions for that.
I will look into that once I'm chanced. In the meantime you can send PR to this effect.
I can do it, I am just not sure I am right with my assumptions. I am new to Adonis.
@ammezie Heads Up: I guess you need to wait for AdonisJS v4.1 which is a breaking changes for exceptions.
Reference: https://github.com/adonisjs/adonis-framework/issues/718 Tagged: v4.1
Alright. Thanks for pointing that out.
Hi,
Does anyone have and example of how to handle errors? Currently I'm attempting to return them in a resolve method.
Ex.
resolve: async (root, { input }, context) => {
const rules = { email: 'required|email|unique:users' }
const validation = await validate(input, rules)
console.log(validation)
if (validation.fails()) {
throw new Error('Test')
}
return await User.create(input)
}
[ { message: 'e.hasOwnProperty is not a function',
field: 'email',
validation: 'ENGINE_EXCEPTION' },
message: 'undefined: 1101e897-ea60-407b-b259-28a159c234c0' ]
Error: [object Object]
at asErrorInstance (/Users/antwaan/Sites/adonisgql/node_modules/graphql/execution/execute.js:545:43)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
Thanks!
@moltar still working on a PR on this? Want to know so as to avoid duplicate efforts.
@ammezie No, not working on this.