You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
try{// Send post request to the API endpoint using Nuxt 3 useFetchconstpath="/api/passwordless/auth/email/";await$fetch(path,{onRequest({ request, options }){console.log("Request:",request);// Set the request headersoptions.headers=options.headers||{};// Addresses the following TypeScript error:// Element implicitly has an 'any' type because expression of type '"Content-Type"' can't be used to index type 'HeadersInit'.//// TODO: Find a better way.(options.headersas{[key: string]: any})["AFB"]="rules";},onRequestError({ request, options, error }){// Handle the request errorsconsole.error("A request error occurred:",error);},onResponse({ request, response, options }){constdata=response._data;console.log("Response data:",data);// Process the response data// A successful response returns a friendly message for the// user. The next step is for the user to check their email// for the magic link to sign in.if(response.ok){// Ignore data.detail bc it's not a friendly message// and comes straight from drfpasswordless.constmessage="Check your email for a link to log in.";console.log("Message:",message);snackbar.add({type: "success",text: message,});}else{// Handle the response errorsconsole.error("A response error occurred (1):","Status code:",response.status,"Status message:",data.detail,);snackbar.add({type: "error",text: "An error occurred. Please try again.",});}},onResponseError({ request, response, options }){// Handle the response errorsconsole.error("A response error occurred (1):","Status code:",response.status,"Status message:",response._data.detail,);},baseURL: config.public.apiBase,method: "POST",body: JSON.stringify(payload),headers: {"Content-Type": "application/json",},mode: "cors",});}catch(error){console.error("An unhandled error occurred:",error);}
Context
index.vue:98 Response data:
POST https://dev.afb.pet/api/passwordless/auth/email/ 400 (Bad Request)
{
"email": [
"Enter a valid email address."
]
}
The text was updated successfully, but these errors were encountered:
delano
changed the title
[bug] Why is an error raised for a bad HTTP status instead of the heandler being called?
[bug] Why is an error raised for a bad HTTP status instead of the handler being called?
Apr 16, 2024
Relevant code
From pages/login/index.vue:
Context
The text was updated successfully, but these errors were encountered: