Proxy for Error Classes
sam-goodwin opened this issue · comments
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) {
}
}
Proxy could work like:
let errorClasses = {};
new Proxy({}, {
get: (_, className) => errorClasses ??= (class extends Error {
constructor(type: string, message: string) { .. }
})
}
Hard parts:
- how do we enumerate all the different errors?
- how do we map AWS's internal error IDs, e.g.
__type: 'com.amazon.coral.validate#ValidationException',
to a class?