Still quite inexperienced and I'm trying to error handle a 400 Bad Request.
I have a site with a search bar.
The value entered into the search bar is then placed into an api url that returns an object.
Whenever a misspelled search value is entered, the site's console returns a 400 Bad Request for the api url.
I also receive the error object below from the api url request.
{
meta: {
code: 400,
errorType: failed_geocode,
errorDetail: Couldn't geocode param near: Jljjl,
requestId: 59208ac96a6071641949481d
},
response: {}
}
What I want to do is use a conditional statement like below to handle this error:
try {
if (400 Bad Request) throw incorrect;
} catch (err) {
document.getElementById('results').innerHTML = Input is + err;
}
I've tried conditional statements like the one's below but it seems like I am unable to access any of the values in the error object that is returned:
if (object.meta.code === 400)
if (object.meta.code !== 200)
if (object === undefined) // or null or 0
How can I put the 400 Bad Request error into the if statement, or is there another way to handle these errors?
Thanks