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

generate server-side exceptions as classes #502

Merged
merged 21 commits into from Feb 21, 2022

Conversation

AllanZhengYP
Copy link
Contributor

@AllanZhengYP AllanZhengYP commented Jan 28, 2022

Issue #, if available:
Related to aws/aws-sdk-js-v3#3261
SSDK generated example: aws/aws-sdk-js-v3#3310

Description of changes:
This change generates server-side exceptions as individual classes. So customers can handle exceptions with ease.
You can view generated code diff at aws/aws-sdk-js-v3#3267

Now the customer can handle the errors without hardcoding the error code:

import {
    InvalidSignatureException,
    UnfoundResourceException,
    FooServiceException
} from "@aws-sdk/client-foo";

try {
    await client.send(operation);
} catch (e) {
    if (e instanceof InvalidSignatureException) {
    // Do something
    } else if (e instanceof UnfoundResourceException) {
    // Do other thing
    } else if (e instanceof FooServiceException) {
    // Unknown exception
    } else {
    // SDK error
    }
}

For SSDK, customer can do the similar:

import { InvalidSignatureException, UnfoundResourceException } from "@aws-sdk/server-foo";
try {
    await operation.handle(...);
} catch (e) {
    if (e instanceof InvalidSignatureException) {
    // Do something
    } else if (e instanceof UnfoundResourceException) {
    // Do other thing
    } else {
    // SDK error
    }
}

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 marked this pull request as ready for review January 28, 2022 02:24
@AllanZhengYP AllanZhengYP requested a review from a team as a code owner January 28, 2022 02:24
@AllanZhengYP AllanZhengYP requested review from adamthom-amzn and gosar and removed request for adamthom-amzn February 1, 2022 19:00
@gosar
Copy link
Contributor

gosar commented Feb 1, 2022

The commit for the generated code linked in the PR description says SdkException. Probably outdated link. It would be with ServiceException, right?

@AllanZhengYP
Copy link
Contributor Author

AllanZhengYP commented Feb 1, 2022

@gosar Yes, they will be renamed to ServiceExceptions. Updated the description.

@AllanZhengYP AllanZhengYP marked this pull request as draft February 9, 2022 21:07
@AllanZhengYP AllanZhengYP marked this pull request as ready for review February 9, 2022 21:10
Copy link
Contributor

@gosar gosar left a comment

Choose a reason for hiding this comment

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

Please update the link in the description of the PR with the latest generated code

@AllanZhengYP AllanZhengYP merged commit 1837734 into smithy-lang:main Feb 21, 2022
srchase pushed a commit to srchase/smithy-typescript that referenced this pull request Mar 17, 2023
This change generates server-side exceptions as individual classes. So customers can handle exceptions with ease.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants