• Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

119
Views
Javascript console.log errors: how to see the real object of the Error

When console.logging errors, the browser prints a differently styled output than if it were a normal object. How can you force Google / Firefox to print the real object of the Error class instead of the stylized less useful 'error' output?

I know for example the object contains e.message and e.response for example, which you can never deduct from the Browsers log outputs.

api
  .post('/post/create', formData)
  .then((res) => {
  })
  .catch((e) => {
    // doesn't print the error object
    // doesn't print the error object
    // doesn't print the error object
    console.log(e)

    // UPDATE, destructuring does print the full Error object
    // UPDATE, destructuring does print the full Error object
    // UPDATE, destructuring does print the full Error object
    console.log('full error object', {e})
  })

Firefox Chrome

Update after approved answer. Now I got the full error object.

enter image description here

9 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Simple solution - log the error object as a property of a plain object

try {
    throw Error("Some error text");
}
catch( error) {
    console.log( {error});
}

This allows you to inspect and expand the structure of an error object in the same way you would any other. Best performed in a browser since code snippets don't provide inspection facilities.

9 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.