absinthe-graphql / absinthe-socket

Core JavaScript support for Absinthe WS-based operations
MIT License
149 stars 75 forks source link

Error maps from the API return as `[object Object]` #39

Closed timhwang21 closed 5 years ago

timhwang21 commented 5 years ago

Seems related to #20 and #29. Also related to phoenixframework/phoenix#3323.

It seems like the various createFooError(errorMessage)s and the various upstream handlers all expect errorMessage to be a string. If my API returns a map instead we get [object Object].

In the other ticket I filed, I post a solution for preprocessing the error message into a string. However, I was wondering if it's reasonable to just check for stringiness in this library, and call JSON.serialize on the message if it's not a string?

A simple example would be changing createRequestError() to be:

const createRequestError = message =>
  new Error(`request: ${typeof message === 'string' ? JSON.stringify(message) : message}`)

(Would obviously benefit from more abstraction!)

mgtitimoli commented 5 years ago

Message must be string by spec.

We could consider adding support to extensions.

mgtitimoli commented 5 years ago

Duplicate of #29 (Let's follow the discussion there)