@@ -4,7 +4,13 @@ import {
44 UnauthorizedError as Auth0UnauthorizedError ,
55} from 'express-oauth2-jwt-bearer'
66
7- import { HttpError , InsufficientScopeError , InternalError , UnauthorizedError } from '@crowd/common'
7+ import {
8+ ConflictError ,
9+ HttpError ,
10+ InsufficientScopeError ,
11+ InternalError ,
12+ UnauthorizedError ,
13+ } from '@crowd/common'
814import { SlackChannel , SlackPersona , sendSlackNotification } from '@crowd/slack'
915
1016/**
@@ -17,6 +23,30 @@ export const errorHandler: ErrorRequestHandler = (
1723 res : Response ,
1824 _next : NextFunction ,
1925) => {
26+ if ( error instanceof ConflictError ) {
27+ req . log . warn ( { context : error . context } , 'Public API conflict' )
28+ sendSlackNotification (
29+ SlackChannel . CDP_LFX_SELF_SERVE_ALERTS ,
30+ SlackPersona . WARNING_PROPAGATOR ,
31+ `Public API Conflict 409: ${ req . method } ${ req . url } ` ,
32+ [
33+ {
34+ title : 'Request' ,
35+ text : `*Method:* \`${ req . method } \`\n*URL:* \`${ req . url } \`` ,
36+ } ,
37+ {
38+ title : 'Conflict' ,
39+ text : `*Message:* ${ error . message } ` ,
40+ } ,
41+ ...( error . context
42+ ? [ { title : 'Context' , text : `\`\`\`${ JSON . stringify ( error . context , null , 2 ) } \`\`\`` } ]
43+ : [ ] ) ,
44+ ] ,
45+ )
46+ res . status ( error . status ) . json ( error . toJSON ( ) )
47+ return
48+ }
49+
2050 if ( error instanceof HttpError ) {
2151 res . status ( error . status ) . json ( error . toJSON ( ) )
2252 return
0 commit comments