File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Response } from "./Response.js" ;
2+
3+ /**
4+ * An (error) response that is thrown. Will be caught by the server and sent to the client.
5+ */
6+ export class ThrowableResponse < T extends Response > extends Error {
7+ public override name = ThrowableResponse . name ;
8+
9+ /**
10+ * The response to send to the client.
11+ */
12+ protected readonly response : T ;
13+
14+ /**
15+ * An optional error to emit on the server’s error event.
16+ */
17+ protected readonly error : Error | null ;
18+
19+ /**
20+ * Create a new throwable response.
21+ * @param response The response to send to the client.
22+ * @param [error] An optional error to emit on the server’s error event.
23+ */
24+ public constructor ( response : T , error ?: Error ) {
25+ super ( ) ;
26+ this . response = response ;
27+ this . error = error ?? null ;
28+ }
29+
30+ public getResponse ( ) : T {
31+ return this . response ;
32+ }
33+
34+ public getError ( ) : Error | null {
35+ return this . error ;
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments