wrap aws-sdk errors

because there are http errors with no message any error reading the
object is wrapped to conform to the @backstage/error assertError checks

Signed-off-by: Manuel Stein <manuel.stein@nokia-bell-labs.com>
This commit is contained in:
Manuel Stein
2022-07-22 18:43:44 +03:00
parent 5f36581151
commit c8196bd37d
3 changed files with 9 additions and 2 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@backstage/plugin-techdocs-node': patch
---
Fix AWS S3 404 NotFound error
When reading an object from the S3 bucket through a stream, the aws-sdk getObject() API may throw a 404 NotFound Error with no error message or, in fact, any sort of HTTP-layer error responses. These fail the @backstage/error's assertError() checks, so they must be wrapped. The test for this case was also updated to match the wrapped error message.
@@ -478,7 +478,7 @@ describe('AwsS3Publish', () => {
await expect(fails).rejects.toMatchObject({
message: expect.stringMatching(
/TechDocs metadata fetch failed; caused by Error: The file .* does not exist/i,
/TechDocs metadata fetch failed; caused by Error: .*/i,
),
});
});
@@ -49,7 +49,7 @@ const streamToBuffer = (stream: Readable): Promise<Buffer> => {
try {
const chunks: any[] = [];
stream.on('data', chunk => chunks.push(chunk));
stream.on('error', reject);
stream.on('error', (e: Error) => reject(new ForwardedError('Unable to read stream', e)));
stream.on('end', () => resolve(Buffer.concat(chunks)));
} catch (e) {
throw new ForwardedError('Unable to parse the response data', e);