title: How can I access HTTP error response body in angular
body: <p>I want to access error response body and show the message in that array</p>
  <pre><code>ERROR:
  Bp {headers: Op, status: 422, statusText: &quot;OK&quot;, url: &quot;https://abc.trade/trade/save-trade&quot;, ok: false, …}
  error: Array(1)
  0:
    errorArgumentsMap: null
    errorCode: &quot;CREATE_ERROR_CODE&quot;
    errorPropagate: null
    fieldName: &quot;&quot;
    message: &quot;trade already exists with id(T4)&quot;
    name: &quot;&quot;
  __proto__: Object
  length: 1
  __proto__: Array(0)
  headers: Op {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
  message: &quot;Http failure response for https://abc.trade/trade/save-trade: 422 OK&quot;
  name: &quot;HttpErrorResponse&quot;
  ok: false
  status: 422
  statusText: &quot;OK&quot;
  url: &quot;https://abc.trade/trade/save-trade&quot;
  </code></pre>
  <p>This is the response I get from API. Now I want to access error.error.message. Below is my code</p>
  <p>---TS File---</p>
  <pre><code>this.createTrade.saveTrade(tradeData).subscribe((data: any)=&gt;{       
          if(data.id){
            console.log('Created Sucessfully')          
          }        
        },
        error =&gt; {        
          if(error){
            let errorMsg = error.error.message;           
            console.log(errorMsg)
          }
        }
  )
  </code></pre>
  <p>---service.ts---</p>
  <pre><code>saveTrade(request: any) {
  const urlList = 'https://abc.trade/trade/save-trade';
  return this.http
    .post&lt;[]&gt;(urlList, request, {
      headers: this.headers
    })
    .pipe(
      map(data =&gt; {
        return data;
      }),
      catchError(this.handleError)
    );   
  </code></pre>
  <p>}</p>
  <p>On sucess it is working. But on error I'm not able to read error.error.message.I even tried accessing error.error[0].message. Could you guys please advise</p>
  <p><a href="https://i.stack.imgur.com/TLM1D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TLM1D.png" alt="enter image description here" /></a></p>