0
I have this generic method that recovers something from the server:
async criate(url: string, object: Object): Promise<any> {
try {
return response = await this.api().post( url, object );
} catch (error) {
console.log( 'API_ERROR: ', error.request.response, 'CODE: ', error.request.status );
}
}
I have this model that consumes the above method:
async login() {
this.loading = true;
try {
const user: User = await this.api.cri<User>(rotaUsuario.login, this.currentUser);
} catch (e) {
console.log( e );
} finally {
this.loading = false;
}
}
And finally the component that consumes the data:
this.store.login().then(() => this.navigation.navigate('Sessao')).catch(() => console.log('error'));
The problem is that when the generic method enters the catch
even so the consuming component calls the then
instead of calling the catch
as I hope.
How to fix this?