Catching business logic specific errors thrown by Durable object RPC Calls from a worker
Original message was deleted
return new Response('This is a result', {status: some_number_you_pick}) just pick a number between 400-499 and make your Worker react to that code accordinglyJSON.stringify()return new Response('This is a result', {status: some_number_you_pick})JSON.stringify()export class HTTPError extends Error {
constructor(message, status) {
super(message)
this.status = status
this.body = { error: { message, status } }
}
}export function throwIf(condition, message, status = 400) {
if (condition) {
throw new HTTPError(message, status)
}
return true
}throwIf(personValue == null && personIDString == null, 'body.personValue or body.personIDString required', 400)