adonis-apollo-server icon indicating copy to clipboard operation
adonis-apollo-server copied to clipboard

Error handling

Open moltar opened this issue 7 years ago • 7 comments

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.

moltar avatar Feb 01 '18 17:02 moltar

I will look into that once I'm chanced. In the meantime you can send PR to this effect.

ammezie avatar Feb 01 '18 17:02 ammezie

I can do it, I am just not sure I am right with my assumptions. I am new to Adonis.

moltar avatar Feb 01 '18 20:02 moltar

@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

kevyworks avatar Feb 06 '18 14:02 kevyworks

Alright. Thanks for pointing that out.

ammezie avatar Feb 06 '18 14:02 ammezie

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!

antwaanh avatar Mar 04 '18 19:03 antwaanh

@moltar still working on a PR on this? Want to know so as to avoid duplicate efforts.

ammezie avatar Mar 06 '18 10:03 ammezie

@ammezie No, not working on this.

moltar avatar Mar 06 '18 13:03 moltar