mock-aws-s3
mock-aws-s3 copied to clipboard
Support NoSuchKey errors for missing objects instead of file IO errors
As reported in https://github.com/goldstack/goldstack/issues/460, this library currently does not throw NoSuchKey errors when an object does not exist.
Workaround: I've written some simple wrappers in: https://github.com/goldstack/goldstack/pull/462/files#diff-3aeb69b76fe6d60e2e86dfce2a619f2ec35df67c272678b7aea057b253aff9a5
if (['headObject', 'getObjectTagging', 'putObjectTagging', 'copyObject'].includes(method)) {
try {
const result = await operation.promise();
if (method === 'headObject' && result === undefined) {
throw new NoSuchKey({
message: 'The specified key does not exist.',
$metadata: {},
});
}
return result;
} catch (e) {
const awsError = e as AWSError;
if (awsError.code === 'NoSuchKey' || awsError.code === 'ENOENT') {
throw new NoSuchKey({
message: e.message,
$metadata: {},
});
}
throw e;
}
}