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

134
Views
how to read response body in catch block in http call angular 2

How can I read the response body in catch block of angular 2 http request. Following is the code that I have so far:

requeueTask(data): Observable<Response>{
        this.setHeaders();
        let url = SharedService.requeueTaskApi;
        return this._http.put(url, data, {headers: this.headers})
                    .map((response: Response) => response)
                    //.do(data => console.log(JSON.stringify(data)))
                    .catch((error: any, response) => {
                        console.log(response);
                        if (error.status < 400 ||  error.status ===500) {
                            return Observable.throw(new Error(error.status));
                        }
                    })
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can catch error like this below:

return this._http.put(url, data, {headers: this.headers})
                .map((response: Response) => response)
                .catch((error: Response) => {
                    console.log(response);
                    if (error.status < 400 ||  error.status ===500) {
                        return Observable.throw(error.json().error || 'Server error');
                    }
                })
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!