#Can't get the body of an error http call

13 messages · Page 1 of 1 (latest)

languid pond
#

Hi 🙂

I have a backend with NestJS that return me a 405 http code with a custom body.

🛑 405 Method Not Allowed

{
    "message": "Event is disabled",
    "name": "Error"
}```

When i call it from my Angular app with the HttpClient, i'm not able to get the body if it's an error.

//src/app/services/core/tickets.service.ts
participate(itemId: number, serial: string) {
const ticket = {itemId, serial};
return this.http.post(${this.url}/tickets/participate, ticket, { observe: 'response', responseType: 'json' });
}

//src/app/home/modals/take-chance.component.ts
this.ticketService.participate(this.detail.id, this.ticketForm.value.serial).pipe(
tap(response => {
console.log('Success', response);
this.close();
}),
catchError((error: any) => {
console.log('Error', error);
// const alert = await this.alertController.create({
// header: 'A Short Title Is Best',
// message: 'A message should be a short, complete sentence.',
// buttons: ['Action'],
// });
// await alert.present();
return of(null);
})
).subscribe();


It's probably a stupid thing i miss but if someone can show me the right way to do that 🙂
iron dome
#

Did you try to access error.message?

languid pond
#

That return me the message of the HttpErrorResponse

#

i'm looking to get the HttpResponse of the call

iron dome
#

what if error.error.message?

languid pond
#
this.ticketService.participate(this.detail.id, this.ticketForm.value.serial).subscribe({
          next: value => {
            console.log('next', value)
          },
          error: error => {
            console.log('error 1', error);
            console.log('error 2', error.error);
            console.log('error 3', error.error.message);
          },
          complete: () => {
            console.log('complete')
          },
        });
#

When i return a 200 from my backend :

#

the payload is present (just in case :))

#

I'm completely stupid ... i had forget that i have an interceptor and i rewritten all error ...

iron dome
#

Yes, I was wondering what that jwt.interceptor was on top of the call stack

languid pond