Kibana plugin handling errors returned by the API

I'm trying to display an error message in my kibana plugin. I do it over http.get(...).then (..).catch( e=>{console.log(e)}). In the browser console, I see, for example, error: bad request and nothing else. I expected to see an object {statusCode: 400, error: "Bad request", message: "some error description"}. At the same time, in the console, when I view the network connection log, I see fetch to my API and see a response in the format {statusCode: 400, error: "Bad request", message: "some error description"}. Where did message go?

console.log is kinda stupid when logging errors, and will often only display e.msg or e.toString(). Which is very misleading.

In case of server-side returned error, The error payload is accessible via error.body

try { 
   await http.fetch(... ) 
} catch(e) {
  console.log(e.body)
}

e.body will contains the payload you see in the network tab ({statusCode: 400, error: "Bad request", message: "some error description"}.)

Thank you! It,s magic.
Now I have on server side

return response.badRequest({
          body: 'My error description message'
        })  

on front (UI) side I have

.catch ( e => {
console.log(e.body)
// my code working with error
});

and I got

{statusCode: 400, error: "Bad Request", message: "My error description message"}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.