Skip to content

Commit a5c70d3

Browse files
razor-xseambot
andauthored
feat: Add SeamHttpInvalidInputError.getValidationErrorMessages (#132)
* feat: Add SeamHttpInvalidInputError.getInputErrorMessages * ci: Format code * Rename to getValidationErrorMessages --------- Co-authored-by: Seam Bot <[email protected]>
1 parent 295dc17 commit a5c70d3

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/lib/seam/connect/api-error-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export interface ApiError {
88
type: string
99
message: string
1010
data?: unknown
11+
validation_errors?: Record<string, { _errors: string[] }>
1112
}

src/lib/seam/connect/seam-http-error.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ export const isSeamHttpUnauthorizedError = (
4646

4747
export class SeamHttpInvalidInputError extends SeamHttpApiError {
4848
override code: 'invalid_input'
49+
readonly #validationErrors: NonNullable<ApiError['validation_errors']>
4950

5051
constructor(error: ApiError, statusCode: number, requestId: string) {
5152
super(error, statusCode, requestId)
5253
this.name = this.constructor.name
5354
this.code = 'invalid_input'
55+
this.#validationErrors = error.validation_errors ?? {}
56+
}
57+
58+
getValidationErrorMessages(paramName: string): string[] {
59+
return this.#validationErrors[paramName]?._errors ?? []
5460
}
5561
}
5662

test/seam/connect/http-error.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ test('SeamHttp: throws SeamHttpInvalidInputError on invalid input', async (t) =>
9292
t.is(err?.statusCode, 400)
9393
t.is(err?.code, 'invalid_input')
9494
t.true(err?.requestId?.startsWith('request'))
95+
t.deepEqual(err?.getValidationErrorMessages('device_ids'), [
96+
'Expected array, received number',
97+
])
9598
})

0 commit comments

Comments
 (0)