What is the problem this feature would solve?
Current Bun.serve.error only provides an Error as a callback while fetch accepts request
Bun.serve({
port: 3000,
fetch(request) {
throw new Error('thing')
},
error(error) {
return new Response('thing')
}
})
This makes error a "generic catch-all function" instead of being able to be tailored to a specific need for each request, similar to fetch. Leaving error unused most of the time
Bun.serve({
port: 3000,
fetch(request) {
try {
throw new Error('thing')
} catch (error) {
return handleErrorForEachRequest(request)
}
},
error(error) {
// Unable to tailor based on request, default to try-catch inside fetch
return new Response('thing')
}
})
What is the feature you are proposing to solve the problem?
Add request as a 2nd parameter to error callback
This wouldn't introduce any breaking change with any prior versions
Bun.serve({
port: 3000,
fetch(request) {
throw new Error('thing')
},
// Request is added here
error(error, request) {
return handleErrorForEachRequest(request)
}
})
What alternatives have you considered?
Keep using try-catch as provided
What is the problem this feature would solve?
Current
Bun.serve.erroronly provides anErroras a callback whilefetchacceptsrequestThis makes
errora "generic catch-all function" instead of being able to be tailored to a specific need for eachrequest, similar tofetch. Leavingerrorunused most of the timeWhat is the feature you are proposing to solve the problem?
Add
requestas a 2nd parameter toerrorcallbackThis wouldn't introduce any breaking change with any prior versions
What alternatives have you considered?
Keep using
try-catchas provided