mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
fix(server): handle graphql bad input error (#10854)
This commit is contained in:
@@ -13,6 +13,7 @@ import { GraphQLError } from 'graphql';
|
||||
|
||||
import { Config } from '../config';
|
||||
import { UserFriendlyError } from '../error';
|
||||
import { isGraphQLBadRequest, mapAnyError } from '../nestjs/exception';
|
||||
import { GQLLoggerPlugin } from './logger-plugin';
|
||||
|
||||
export type GraphqlContext = {
|
||||
@@ -65,6 +66,15 @@ export type GraphqlContext = {
|
||||
formattedError.extensions = error.originalError.toJSON();
|
||||
formattedError.extensions.stacktrace = error.originalError.stack;
|
||||
return formattedError;
|
||||
} else if (
|
||||
error instanceof GraphQLError &&
|
||||
isGraphQLBadRequest(error)
|
||||
) {
|
||||
const err = mapAnyError(error);
|
||||
// @ts-expect-error allow assign
|
||||
formattedError.extensions = err.toJSON();
|
||||
formattedError.extensions.stacktrace = err.stack;
|
||||
return formattedError;
|
||||
} else {
|
||||
// @ts-expect-error allow assign
|
||||
formattedError.message = 'Internal Server Error';
|
||||
|
||||
Reference in New Issue
Block a user