Question

Convert JSON status code ("400") to object

  • 18 March 2021
  • 2 replies
  • 15 views

What Javascript/other tools would you use to convert a JSON response code (“400”) into an object? That is, if there’s no other content, but I want to “generate” content out of the status code.


2 replies

Userlevel 1

Maybe try using try-catch to handle that error?

 

In the catch section of your code, you should be able to use the error message. 

 

Here's a link to try-catch:

https://www.w3schools.com/js/js_errors.asp

Userlevel 1
Badge +4

Hey @averycampbell, hope you’re well, I just wanted to check in here!

Were you able to get things going with the information from Jhealyn, or can we still help here?

I believe the Try-Catch recommendation would be a solid place to start for catching errors. The main difference from the example is that you want to return a JSON object vs generating HTML into an HTML p tag.

Reply