DEV Community

loading...

How to throwing our own errors

ashrafulislam profile image Ashraful Islam ・1 min read

Throwing our own errors
What if json is syntactically correct, but doesn’t have a required name property?

Discussion (1)

Collapse
_gdelgado profile image
Gio • Edited
const data = JSON.parse(jsonString)

if (!data.requiredName) {
  throw new Error('missing required field')
}
Enter fullscreen mode Exit fullscreen mode
Forem Open with the Forem app