mirror of
https://github.com/wassname/talk.git
synced 2026-07-12 09:23:09 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
+7
-11
@@ -1,23 +1,21 @@
|
||||
const {forEachField} = require('./utils');
|
||||
const {maskErrors} = require('graphql-errors');
|
||||
const { forEachField } = require('./utils');
|
||||
const { maskErrors } = require('graphql-errors');
|
||||
const errors = require('../errors');
|
||||
const {Error: {ValidationError}} = require('mongoose');
|
||||
const { Error: { ValidationError } } = require('mongoose');
|
||||
|
||||
// If an APIError happens in a mutation, then respond with `{errors: Array}`
|
||||
// according to the schema.
|
||||
const decorateWithMutationErrorHandler = (field) => {
|
||||
const decorateWithMutationErrorHandler = field => {
|
||||
const fieldResolver = field.resolve;
|
||||
field.resolve = async (obj, args, ctx, info) => {
|
||||
try {
|
||||
return await fieldResolver(obj, args, ctx, info);
|
||||
}
|
||||
catch(err) {
|
||||
} catch (err) {
|
||||
if (err instanceof errors.APIError) {
|
||||
return {
|
||||
errors: [err]
|
||||
errors: [err],
|
||||
};
|
||||
} else if (err instanceof ValidationError) {
|
||||
|
||||
// TODO: wrap this with one of our internal errors.
|
||||
throw err;
|
||||
}
|
||||
@@ -32,9 +30,8 @@ const decorateWithMutationErrorHandler = (field) => {
|
||||
* @param {GraphQLSchema} schema the schema to decorate
|
||||
* @return {void}
|
||||
*/
|
||||
const decorateWithErrorHandler = (schema) => {
|
||||
const decorateWithErrorHandler = schema => {
|
||||
forEachField(schema, (field, typeName) => {
|
||||
|
||||
// Handle mutation errors.
|
||||
if (typeName === 'RootMutation') {
|
||||
decorateWithMutationErrorHandler(field);
|
||||
@@ -42,7 +39,6 @@ const decorateWithErrorHandler = (schema) => {
|
||||
|
||||
// If we are in production mode, don't show server errors to the front end.
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
|
||||
// Mask errors that are thrown if we are in a production environment.
|
||||
maskErrors(field);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user