Replies: 1 comment
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having an issue trying to catch an exception from the Lightsail SDK (v3) using
instanceof
in my typescript CLI app I'm running with NodeJS via ts-node. I decided to post a discussion question instead of an issue because I'm guessing there's a good chance I just don't know something about typescript or I misunderstood the docs in some way.Here are my versions:
Issue: sending a
GetInstanceCommand
orGetStaticIpCommand
for a resource I know doesn't exist doesn't return aNotFoundException
like I expect (err instance NotFoundException
). The only exception I'm able to detect usinginstanceof
isLightsailServiceException
(the exception base class). I would like to be able to detect the NotFoundException usinginstanceof
and the specific exception type instead of comparing the error's "name" property to the string "DoesNotExist" (which isn't in the docs at all - had to just look at some errors to see what to look for) or only ever looking forLightsailException
and just assuming it's because it wasn't found.Docs:
instanceof ExceptionType
: https://aws.amazon.com/blogs/developer/service-error-handling-modular-aws-sdk-js/Based on the exception detail, it sort of looks like it could actually "be a NotFoundException" (based on the
__type
property), but that typescript (or something I've done wonky) just can't differentiate between the instance and it's base class:Is there something obvious I'm missing or is it known/intended that you can't actually check the instance of the specific exception, but only the base exception type using
instanceof
?Beta Was this translation helpful? Give feedback.
All reactions