Skip to content

Commit 69e3597

Browse files
committed
handle throwable response in route handling
1 parent ebdc8e6 commit 69e3597

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import packageJson from "../package.json" with {type: "json"};
44
import {Request} from "./Request.js";
55
import {EmptyResponse} from "./response/index.js";
66
import {Response} from "./response/Response.js";
7+
import {ThrowableResponse} from "./response/ThrowableResponse.js";
78
import {RouteRegistry} from "./routing/RouteRegistry.js";
89
import {ServerErrorRegistry} from "./ServerErrorRegistry.js";
910

@@ -100,7 +101,13 @@ class Server extends EventEmitter<Server.Events> {
100101
response = await this.routes.handle(apiRequest);
101102
}
102103
catch (e) {
103-
if (e instanceof RouteRegistry.NoRouteError)
104+
if (e instanceof ThrowableResponse) {
105+
response = e.getResponse();
106+
const cause = e.getError();
107+
if (cause !== null)
108+
this.emit("error", cause);
109+
}
110+
else if (e instanceof RouteRegistry.NoRouteError)
104111
response = this.errors._get(ServerErrorRegistry.ErrorCodes.NO_ROUTE, apiRequest);
105112
else {
106113
this.emit("error", e as any);

0 commit comments

Comments
 (0)