How to override response after "before" hook but before "after" hook?

E.g. I would like to just return something else when I get this internal Better Auth Error returned:
body: {
  code: 'USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL',
  message: 'User already exists. Use another email.'
}


Basically I want below to be returned in the response instead:
body: {
  code: 'EMAIL_SENT_TO_USER',
  message: 'Email sent to user'
}


Although a bit odd, doing below used to work
throw new APIError("OK", {
  code: "EMAIL_SENT_TO_USER",
  message: "Email sent to user",
});
Was this page helpful?