0

I'm having a problem when I need to handle an error in an Angular service. In my scenario, a 404 return is not a mistake for me and I need to return Null to my front. My problem is that I still get the error in my console GET http://localhost:9000/api/funcionarios/user/3 404 (Not Found). Every time an error occurs in my application, a service of mine is triggered generating a log (which in this scenario should not occur)

component.ts

this.funcionario.findByUser(parseInt(account.id, 10)).subscribe((r) => {
    this.setFuncionario(r.body);
}, (err) => {
    this.setFuncionario(null);
});

service.ts

findByUser(id: number): Observable<EntityResponseType> {
    return this.http
        .get<Funcionario>(`${this.resourceUrlByUser}/${id}`, {
            observe: 'response'
        })
        .map((res: EntityResponseType) => res);
}

The result is expected, but you are generating these error logs. Any idea?

Thanks

  • 1
    Possible duplicate of [Eliminate 404 url error in console?](https://stackoverflow.com/questions/12915582/eliminate-404-url-error-in-console) – Quentin Jul 31 '18 at 13:39
  • 1
    Curious as to why you want to hide the errors from the console? If you go google search something while your console is open, you'll be bombarded with errors. It's just the way things are. – Woohoojin Jul 31 '18 at 13:41
  • @ChristianScillitoe In my case, not returning anything is not a mistake but an expected business rule. So I guess I should treat this case in the backend, correct? – Bráulio Figueiredo Jul 31 '18 at 14:02
  • @Quentin Thanks for your help. In the link you reported apparently the problem was that the user did not want the error message. In my case a null response is not an error but a result expected by my application. I believe in this case that I should do the treatment in the backend, correct? – Bráulio Figueiredo Jul 31 '18 at 14:06

1 Answers1

0

In my case I have this: If exists a funcionario, return "funcionario: {<object funcionario>}", but if not existis 404

I'm working on the front if the user has an funcionario do something, otherwise I do something different

I replace my code searching for user. if user have a funcionario, return a user object "user: {funcionario: <object funcionario>}", if not exists "user: {funcionario: null}"

Thank you for your cooperation.