Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected Error format when login fails #2328

Open
bsylvain opened this issue Sep 28, 2021 · 7 comments
Open

Expected Error format when login fails #2328

bsylvain opened this issue Sep 28, 2021 · 7 comments

Comments

@bsylvain
Copy link

bsylvain commented Sep 28, 2021

According to documentation, when login fails, the login controller expect to have the message in reason.error :

try {
      await this.session.authenticate('authenticator:devise', identification, password);
    } catch(error) {
      this.errorMessage = error.error || error;
    }

My error payload in the response to an invalid login is just :
{error:"Mail or password incorrect"}

When a login fail, the error message remain empty

My question is : how is it supposed to be formated? Is it an ember side problem or a server side problem ?

@BobrImperator
Copy link
Collaborator

Could you share what is the error that you receive in the catch block?
At a glance when looking at devise authenticator, it looks like ESA might be forwarding a not parsed response.

@bsylvain
Copy link
Author

image

@BobrImperator
Copy link
Collaborator

It'll be a bit roundabout then for you, but what you're receiving is the raw fetch response.
You should be able to do something like this in your catch block:

.catch((response) => {
   const error = response.json();
   
   this.errorMessage = error.error;
})

@bsylvain
Copy link
Author

The value is still undefined.

@BobrImperator
Copy link
Collaborator

Hmm... so there's nothing returned when you call json() on the response?
Mind that json() returns a promise and I've made a small mistake there as well:

.catch((response) => response.json())
.catch((response) => {   
   this.errorMessage = response.error;
})

@bsylvain
Copy link
Author

I'm trying multiple thing with chained then, but it does not works apparently

@bsylvain
Copy link
Author

Ok so the answer was this :

       .catch((response) =>  response.json() )
      .then((response) => {   
        this.set('errorMessage',response.error)
      });

Thanks for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants