Here is my fast API endpoint:
@app.post("/api/signup", status_code=status.HTTP_200_OK)
async def signup( credentials : signupcred ):
try:
print(credentials.email, credentials.password1, credentials.name )
response = account.create(email= credentials.email, password= credentials.password1, name = credentials.name , user_id= ID.unique() )
return {response}
except Exception as e:
raise HTTPException(status_code= status.HTTP_403_FORBIDDEN) # Return an appropriate error status code
When an exception is raised, I want to display the response on the front end. The response provides a detailed explanation of the error and I don't want to send an HTTP error code to the user.
This is my front end code:
const handlesignup = async (e: any) => {
e.preventDefault();
setLoading((loading) => !loading);
try {
const signupresponse = await axios.post("/api/signup", {
email: signupemail,
password1: password1,
name: name,
}); // Send as query paramers );
// const loginresponse = await axios.post('/api/login', {email, password} )// Send as query paramers );
// setIsloggedin(()=> true)
router.replace("/dashboard");
setLoading((loading) => !loading);
} catch (error) {
alert(error);
}
};
The console.log feature doesn't work due to using Next.js with a FastAPI backend. I simply want to display the response from the create function on the front end so users can understand why an error occurred. Currently, the alert displays: AxiosError: Request failed with status code 403