Skip to content

Commit d85a62a

Browse files
committed
fix orError handler
1 parent 1d25adc commit d85a62a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/http-exception-plugin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ export const httpExceptionPlugin = () =>
1818
headers: { 'Content-Type': 'application/json' },
1919
});
2020
})
21-
.onError(({ error, set }) => {
21+
.onError({ as: 'scoped' }, ({ error, set }) => {
2222
if (error instanceof HttpException) {
23+
set.headers['content-type'] = 'application/json; charset=utf-8'
2324
set.status = error.statusCode;
2425
return error.toBody();
2526
}
27+
2628
set.status = 500;
27-
return { statusCode: 500, message: 'Internal server error' };
29+
const message = error instanceof Error ? error.message : 'Internal server error';
30+
return { statusCode: 500, message };
2831
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
"outDir": "dist",
2626
"types": ["bun-types"]
2727
},
28-
"exclude": ["dist", "examples", "test"]
28+
"exclude": ["dist", "example", "test"]
2929
}

0 commit comments

Comments
 (0)