onAPIError not working

Hello, When i use onAPIError in the auth config and try to log the error there is no logs in the console. Is there a way to use it ? I followed the docs
11 Replies
KiNFiSH
KiNFiSH6mo ago
can u pls share how you actually configured it
SxYxuse
SxYxuseOP6mo ago
Yes sure, like in the docs:
import { betterAuth } from "better-auth";
export const auth = betterAuth({
//… code above
onAPIError: {
throw: true,
onError: (error, ctx) => {
// Custom error handling
console.error("Auth error:", error);
},
errorURL: "/auth/error"
},
})
import { betterAuth } from "better-auth";
export const auth = betterAuth({
//… code above
onAPIError: {
throw: true,
onError: (error, ctx) => {
// Custom error handling
console.error("Auth error:", error);
},
errorURL: "/auth/error"
},
})
KiNFiSH
KiNFiSH6mo ago
can u toggle the throw to false .. ig it is been throwing an error before it is catching and logging it
SxYxuse
SxYxuseOP6mo ago
Same issue I try with auth.api.checkOrganizationSlug with an existing slug to get an error It don’t work But I get the ApiError in the console like before Seem the onAPIError is not reached Will you fix this issue in next release ?
KiNFiSH
KiNFiSH5mo ago
yeah yeah def.
SxYxuse
SxYxuseOP5mo ago
@bekacru sorry for the ping, should be great when onAPIError is fixed that we can transform the error like rebuild it and than rethrow it
bekacru
bekacru5mo ago
will do!
srd
srd5mo ago
Hey, do you have an idea on when this will be looked at?
Sebastian
Sebastian5mo ago
hey, this is pretty important to work.. @bekacru is this getting fixed in 1.2.8?
bekacru
bekacru5mo ago
I'll take a look. This should have been fixed but curious what's your use case?
Sebastian
Sebastian5mo ago
we've migrated from nhost and hasura and now in prod with better-auth, and we need custom pages for UX instead of the stock better-auth ones. Currently, the errorURL doesn't work, not for OAuth callback and also not when throwing in model hooks.

Did you find this page helpful?