Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clients): generate service exceptions as classes #3267

Merged
merged 2 commits into from Feb 21, 2022

Conversation

AllanZhengYP
Copy link
Contributor

@AllanZhengYP AllanZhengYP commented Jan 29, 2022

Issue

#1506
#2007

Associated with smithy-lang/smithy-typescript#502
Followup to #3261

Description

Generate server-side exceptions as classes extended from ServiceException base class. Now you can handle individual service exceptions without hardcoding the error code:

import { ResourceNotFoundException, ServiceException, FooServiceException } from "@aws-sdk/client-foo";

try {
    await client.send(operation);
} catch (e) {
    if (e instanceof ResourceNotFoundException) {
    // Handle resource not found exception
    } else if (e instanceof FooServiceException) {
    // Handle all other service exceptions
    } else {
    // Handle errors from SDK
    }
}

Testing

  • Integration Test
  • Unit test
  • Protocol Test
  • API Reference Generation
yarn test:integration:legacy
yarn run v1.22.17
$ cucumber-js --fail-fast
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

150 scenarios (150 passed)
523 steps (523 passed)
1m40.999s
Done in 102.91s.

Additional context

Add any other context about the PR here.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@AllanZhengYP AllanZhengYP requested a review from a team as a code owner January 29, 2022 01:19
@keverall
Copy link

aws/aws-sdk-js-team please review and fix it so we don't have to use the horrible ANY type on Cognito error any longer.

@moltar
Copy link

moltar commented Feb 2, 2022

Amazing! Can't wait for this to be released, so we don't have to mess around with typecasting and other error-prone solutions.

Copy link
Member

@trivikr trivikr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@AllanZhengYP AllanZhengYP merged commit ca64fee into aws:main Feb 21, 2022
@github-actions
Copy link

github-actions bot commented Mar 8, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants