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

Proxy for Error Classes #10

Open
sam-goodwin opened this issue Jan 18, 2023 · 1 comment
Open

Proxy for Error Classes #10

sam-goodwin opened this issue Jan 18, 2023 · 1 comment

Comments

@sam-goodwin
Copy link
Owner

Can we generate some types for the various AWS SDK errors, e.g. ConditionCheckFailed and then provide a proxy that lazily instantiates a class when accessed?

const dynamo = new AWS.DynamoDB();

try {
  await dynamo.putItem({ .. })
} catch (err) {
  if (err instanceof AWS.DynamoDB.ConditionCheckFailed) {
    
  }
}
@sam-goodwin
Copy link
Owner Author

Proxy could work like:

let errorClasses = {};

new Proxy({}, {
  get: (_, className) => errorClasses ??= (class extends Error {
    constructor(type: string, message: string) { .. }
  })
}

Hard parts:

  1. how do we enumerate all the different errors?
  2. how do we map AWS's internal error IDs, e.g. __type: 'com.amazon.coral.validate#ValidationException', to a class?

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

No branches or pull requests

1 participant