개발 모드를 활성화하려면 development: true 를 설정합니다.
ts
Bun.serve({
development: true,
fetch(req) {
throw new Error("woops!");
},
});개발 모드에서 Bun 은 내장 오류 페이지를 사용하여 브라우저에서 오류를 표시합니다.
error 콜백
서버 측 오류를 처리하려면 error 핸들러를 구현합니다. 이 함수는 오류 발생 시 클라이언트에 제공할 Response 를 반환해야 합니다. 이 응답은 development 모드에서 Bun 의 기본 오류 페이지를 대체합니다.
ts
Bun.serve({
fetch(req) {
throw new Error("woops!");
},
error(error) {
return new Response(`<pre>${error}\n${error.stack}</pre>`, {
headers: {
"Content-Type": "text/html",
},
});
},
});