File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export const GRAPHQL_ERROR_CODES = [
1010] ;
1111
1212export const PRESERVED_STATUS_CODES = [
13+ HttpStatus . BAD_REQUEST ,
1314 HttpStatus . UNAUTHORIZED ,
1415 HttpStatus . FORBIDDEN ,
1516] as const ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { GraphQLError } from 'graphql';
44
55import { PRESERVED_STATUS_CODES } from './exception.constant' ;
66import {
7+ getHttpExceptionCode ,
78 isBaseException ,
89 isGraphqlOriginalError ,
910 isHttpException ,
@@ -26,6 +27,14 @@ const determineErrorCondition = (error: GraphQLError) => {
2627 } ;
2728 }
2829
30+ if ( isHttpException ( error . originalError ) ) {
31+ const status = error . originalError . getStatus ( ) ;
32+ return {
33+ errorStatus : status ,
34+ errorCode : getHttpExceptionCode ( status ) ,
35+ } ;
36+ }
37+
2938 return {
3039 errorStatus : HttpStatus . INTERNAL_SERVER_ERROR ,
3140 errorCode : 'INTERNAL_SERVER_ERROR' ,
Original file line number Diff line number Diff line change 1- import { HttpException } from '@nestjs/common' ;
1+ import { HttpException , HttpStatus } from '@nestjs/common' ;
22
33import { GraphQLErrorExtensions } from 'graphql' ;
44
@@ -23,3 +23,7 @@ export const isBaseException = (
2323export const isHttpException = ( error : unknown ) : error is HttpException => {
2424 return error instanceof HttpException ;
2525} ;
26+
27+ export const getHttpExceptionCode = ( status : number ) : string => {
28+ return HttpStatus [ status ] || 'HTTP_ERROR' ;
29+ } ;
You can’t perform that action at this time.
0 commit comments