From nodejs/node#12729 (comment)
Node.js errors by convention may have a code property with a value that can be tested programmatically, as a more reliable alternative to comparing error message strings. To encourage N-API add-ons to conform to that convention, we could add APIs like napi_create_error_with_code() and napi_throw_error_with_code() that take the code value as another parameter.