Skip to content

Commit 611126e

Browse files
committed
chore: improve message body
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
1 parent c3e7036 commit 611126e

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

backend/src/api/public/middlewares/errorHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ export const errorHandler: ErrorRequestHandler = (
2424
_next: NextFunction,
2525
) => {
2626
if (error instanceof ConflictError) {
27-
const memberIds = (error as ConflictError & { memberIds?: string[] }).memberIds
28-
req.log.warn({ memberIds }, 'Public API conflict')
27+
req.log.warn({ context: error.context }, 'Public API conflict')
2928
sendSlackNotification(
3029
SlackChannel.CDP_LFX_SELF_SERVE_ALERTS,
3130
SlackPersona.WARNING_PROPAGATOR,
@@ -39,7 +38,9 @@ export const errorHandler: ErrorRequestHandler = (
3938
title: 'Conflict',
4039
text: `*Message:* ${error.message}`,
4140
},
42-
...(memberIds ? [{ title: 'Member IDs', text: memberIds.join(', ') }] : []),
41+
...(error.context
42+
? [{ title: 'Context', text: `\`\`\`${JSON.stringify(error.context, null, 2)}\`\`\`` }]
43+
: []),
4344
],
4445
)
4546
res.status(error.status).json(error.toJSON())

backend/src/api/public/v1/members/resolveMember.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { z } from 'zod'
44
import { ConflictError, NotFoundError } from '@crowd/common'
55
import { findMemberIdsByIdentities, optionsQx } from '@crowd/data-access-layer'
66
import { IMemberIdentity, MemberIdentityType, PlatformType } from '@crowd/types'
7-
87
import { ok } from '@/utils/api'
98
import { validateOrThrow } from '@/utils/validation'
109

@@ -32,13 +31,7 @@ export async function resolveMemberByIdentities(req: Request, res: Response): Pr
3231
if (memberIds.length === 0) {
3332
throw new NotFoundError('Member not found')
3433
} else if (memberIds.length > 1) {
35-
const error = new ConflictError('Conflicting identities')
36-
Object.defineProperty(error, 'memberIds', {
37-
value: memberIds,
38-
enumerable: false,
39-
configurable: true,
40-
})
41-
throw error
34+
throw new ConflictError('Conflicting identities', { memberIds })
4235
}
4336

4437
const memberId = memberIds[0]

services/libs/common/src/errors/http.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ export class NotFoundError extends HttpError {
7070
export class ConflictError extends HttpError {
7171
readonly code = 'CONFLICT'
7272
readonly status = 409
73+
readonly context?: Record<string, unknown>
7374

74-
constructor(message = 'Conflict') {
75+
constructor(message = 'Conflict', context?: Record<string, unknown>) {
7576
super(message)
77+
this.context = context
7678
}
7779
}
7880

0 commit comments

Comments
 (0)