Commit 4169e31a authored by Jure's avatar Jure

Merge branch 'error-stack' into 'master'

chore(server): print stack trace when there's an error

See merge request !569
parents 20e0d639 1b5c78ae
Pipeline #13111 passed with stages
in 10 minutes and 34 seconds
const passport = require('passport')
const { ApolloServer } = require('apollo-server-express')
const isEmpty = require('lodash/isEmpty')
const logger = require('@pubsweet/logger')
const errors = require('@pubsweet/errors')
......@@ -34,7 +35,7 @@ const api = app => {
loaders: loaders(),
}),
formatError: err => {
const error = err.originalError || err
const error = isEmpty(err.originalError) ? err : err.originalError
logger.error(error.message, { error })
......@@ -42,10 +43,7 @@ const api = app => {
pubsweetError => error instanceof pubsweetError,
)
// err is always a GraphQLError which should be passed to the client
if (
Object.keys(err.originalError).length !== 0 &&
!isPubsweetDefinedError
)
if (!isEmpty(err.originalError) && !isPubsweetDefinedError)
return {
name: 'Server Error',
message: 'Something went wrong! Please contact your administrator',
......
......@@ -33,7 +33,7 @@ describe('GraphQL errors', () => {
expect(body.errors).toHaveLength(1)
expect(body.errors).toContainEqual({
message: 'Cannot query field "invalidProperty" on type "User".',
name: 'GraphQLError',
name: 'ValidationError',
extensions: {
code: 'GRAPHQL_VALIDATION_FAILED',
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment