Skip to content

Documentation on error handling using instanceof vs. name property #7149

@vobarian

Description

@vobarian

Describe the issue

I am seeing conflicting advice, and would like clarification.

In this repo, ERROR_HANDLING.md, under "Handling service returned errors" [1]:

you can use switches to handle errors based on the error name. instanceof checks are not recommended for error handling due to the possibility of prototype mismatch caused by nesting or other forms of copying/duplication.

But in this AWS Blog, it is all about how we can now use instanceof and implies this is preferable. [2]

In the version 3.53.0 of the modular AWS SDK for JavaScript (v3), we introduced concrete classes for AWS service exceptions which support asserting service exceptions with instanceof operator. In this post, we cover how to use it and how it improves the error handling experience.

Links

[1]
https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/ERROR_HANDLING.md#handling-service-returned-errors
[2]
https://aws.amazon.com/blogs/developer/service-error-handling-modular-aws-sdk-js/

Metadata

Metadata

Labels

documentationThis is a problem with documentation.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions