Skip to content

Commit d842632

Browse files
committed
feat: add ProblemDetailError
1 parent 1ba83b5 commit d842632

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

hello/errors/ProblemDetail.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { Type, type Static } from '@sinclair/typebox'
22
import { Context } from '../Context.js'
33
import { HttpStatusCode, StatusCode } from './StatusCode.js'
44

5+
/**
6+
* Can be used to throw an error with a Problem Detail object.
7+
*/
8+
export class ProblemDetailError extends Error {
9+
public readonly problem: Static<typeof ProblemDetail>
10+
constructor(problem: Omit<Static<typeof ProblemDetail>, '@context'>) {
11+
super(problem.title)
12+
this.problem = { '@context': Context.problemDetail.toString(), ...problem }
13+
this.name = 'ProblemDetailError'
14+
}
15+
}
16+
517
/**
618
* Problem Details Object
719
*

0 commit comments

Comments
 (0)