Hey folks,
I’m using Supabase with SvelteKit for auth and database operations.
Can you let me know if the code below is a good way to handle Supabase errors and show appropriate messages to users for common scenarios?
<script>
// u/ts-nocheck
import { supabase } from "$lib/supabaseClient";
// u/ts-nocheck
const AUTH_ERRORS = {
'429': "You're moving a bit fast! Please wait a moment before trying again.",
'422': "That email doesn't look quite right. Double-check it?",
'network_error': "We're having trouble reaching our servers. Check your connection.",
'default': "Something went wrong on our end. Please try again later."
};
let email=''
let errMsg=''
let successMsg=''
try{
const handleSubmit=async()=>{
const {error}=await supabase.auth.signInWithOtp({
email,
options:{
emailRedirectTo:`${window.location.origin}/callback`
}
})
if(error){
errMsg=AUTH_ERRORS[error.status] || AUTH_ERRORS['default']
console.error("Supabase Error:", error)
return
}
successMsg="Awesome, kinfdly check your email for the next steps!"
email=''
}
}
catch(err){
console.error("Runtime Error", err)
errMsg = "Connection failed. Please try again later.";
}
</script>
Looking forward to suggestions !
Sundaram_2911 is seeking advice on whether their current method of handling Supabase errors in a SvelteKit application is effective. They provided a code snippet that maps common error codes to user-friendly messages and asked for suggestions on improving error handling during authentication and database operations.