Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

666
Views
Angular: How to catch Http Status Code of a failed http.get() method

I have an http.get() method which tries to query a backend API. Given an Id in Frontend, enable a property in the database (this is handled by the backend) I implemented the http method this way:

home.ts

this.service.getZ(id).subscribe((event:any)=>console.log(event))

service.ts

 getz(id):
    return http.get('url'+id,{reportProgress: true,
   responseType: 'text'
}).

Now I need to catch what http status code the backend is sending as I need this status code (like http 200, http 500) to enable another button in the frontend. But for some reason I am just not able to capture the http status in the 'event' variable in the home.ts (as shown above). In console, i get this message: enter image description here

But I am just enable to extract the http status code into a variable. Any suggestions?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Because the handler is only invoke call succeeds. For error there is one more callback. so change your code to :-

this.service.getZ(id).subscribe(
   (event:any)=>console.log(event),
   (err) => console.log(err.statusCode)
)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!