1
1
import { ApolloServerErrorCode as ApolloCode } from '@apollo/server/errors' ;
2
- import { Inject , Injectable } from '@nestjs/common' ;
2
+ import { ArgumentsHost , Inject , Injectable } from '@nestjs/common' ;
3
3
// eslint-disable-next-line no-restricted-imports
4
4
import * as Nest from '@nestjs/common' ;
5
5
import { isNotFalsy , setHas , setOf , simpleSwitch } from '@seedcompany/common' ;
6
6
import { GraphQLError } from 'graphql' ;
7
7
import { uniq } from 'lodash' ;
8
8
import {
9
9
AbstractClassType ,
10
+ DuplicateException ,
10
11
Exception ,
11
12
getParentTypes ,
12
13
getPreviousList ,
13
14
JsonSet ,
14
15
} from '~/common' ;
15
16
import type { ConfigService } from '~/core' ;
16
17
import * as Neo from '../database/errors' ;
18
+ import { ExclusivityViolationError } from '../edgedb/exclusivity-violation.error' ;
17
19
import { isSrcFrame } from './is-src-frame' ;
18
20
import { normalizeFramePath } from './normalize-frame-path' ;
19
21
@@ -29,14 +31,14 @@ export interface ExceptionJson {
29
31
export class ExceptionNormalizer {
30
32
constructor ( @Inject ( 'CONFIG' ) private readonly config ?: ConfigService ) { }
31
33
32
- normalize ( ex : Error ) : ExceptionJson {
34
+ normalize ( ex : Error , context ?: ArgumentsHost ) : ExceptionJson {
33
35
const {
34
36
message = ex . message ,
35
37
stack = ex . stack ,
36
38
code : _ ,
37
39
codes,
38
40
...extensions
39
- } = this . gatherExtraInfo ( ex ) ;
41
+ } = this . gatherExtraInfo ( ex , context ) ;
40
42
return {
41
43
message,
42
44
code : codes [ 0 ] ,
@@ -52,7 +54,10 @@ export class ExceptionNormalizer {
52
54
} ;
53
55
}
54
56
55
- private gatherExtraInfo ( ex : Error ) : Record < string , any > {
57
+ private gatherExtraInfo (
58
+ ex : Error ,
59
+ context ?: ArgumentsHost ,
60
+ ) : Record < string , any > {
56
61
if ( ex instanceof Nest . HttpException ) {
57
62
return this . httpException ( ex ) ;
58
63
}
@@ -87,10 +92,16 @@ export class ExceptionNormalizer {
87
92
} ;
88
93
}
89
94
95
+ if ( ex instanceof ExclusivityViolationError ) {
96
+ ex = DuplicateException . fromDB ( ex , context ) ;
97
+ }
98
+
90
99
if ( ex instanceof Exception ) {
91
100
const { name, message, stack, previous, ...rest } = ex ;
92
101
return {
102
+ message,
93
103
codes : this . errorToCodes ( ex ) ,
104
+ stack,
94
105
...rest ,
95
106
} ;
96
107
}
0 commit comments