Reputation: 1
I had this code:
try {
return await this.client.send(command, options)
} catch (error: unknown) {
if (error instanceof ServiceException) {
throw this.handleError(error)
}
throw new ClientError('Unknown error', 500)
}
As I can understand from here, on SDK v3 we can now handle errors by using the instanceof implementation. So, I decide to have an abstract class where client is abstract and is one of AWS SDK clients. So, what I do here, is that instead of use client exceptions per service, to use the abstract ServiceException of @smithy/smithy-client. I decide this because as you can see, every aws-client extends this class.
My Jest tests are all passing. The above code looks correct. The problem is that because I have this code on a private npm package, when I install the package on my project, and then use it, the code does not get inside this if statement, despite the fact that the error is instance of InvalidParameterException which is instance of CognitoIdentityProviderServiceException which is also instance of ServiceException.
Why is this happening?
Upvotes: 0
Views: 454
Reputation: 20
This may be happening due to the differences in ServiceException
class between your project and your private npm package.
To solve your issue you can try to make use of the peerDependencies
in the package.json file in you private npm package
{
"peerDependencies": {
"@smithy/smithy-client": "^1.0.0"
}
}
Here is a link to a StackOverflow answer for reference.
Upvotes: 0