Merge pull request #12796 from nokia/fix-techdocs-awsS3-err-without-message

wrap aws-sdk errors
This commit is contained in:
Ben Lambert
2022-07-26 09:46:46 +02:00
committed by GitHub
3 changed files with 11 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: Unable to read stream; caused by Error: The file invalid/triplet/path/techdocs_metadata.json does not exist',
),
});
});
@@ -49,7 +49,9 @@ 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);