From 6e9e82b99de658f610553df6913da60fc1154468 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sun, 28 Nov 2021 13:33:11 -0700 Subject: [PATCH] Review feedback. Signed-off-by: Eric Peterson --- .../techdocs-common/src/stages/publish/local.ts | 4 +++- .../src/cache/TechDocsCache.test.ts | 4 +--- .../techdocs-backend/src/cache/TechDocsCache.ts | 16 ++++++---------- .../src/cache/cacheMiddleware.ts | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/techdocs-common/src/stages/publish/local.ts b/packages/techdocs-common/src/stages/publish/local.ts index 91a9b57a9e..fc64776e4c 100644 --- a/packages/techdocs-common/src/stages/publish/local.ts +++ b/packages/techdocs-common/src/stages/publish/local.ts @@ -132,7 +132,9 @@ export class LocalPublish implements PublisherBase { }); return { - remoteUrl: `${techdocsApiUrl}/static/docs/${entity.metadata.name}`, + remoteUrl: `${techdocsApiUrl}/static/docs/${encodeURIComponent( + entity.metadata.name, + )}`, objects, }; } diff --git a/plugins/techdocs-backend/src/cache/TechDocsCache.test.ts b/plugins/techdocs-backend/src/cache/TechDocsCache.test.ts index 17056fc442..17613e1b58 100644 --- a/plugins/techdocs-backend/src/cache/TechDocsCache.test.ts +++ b/plugins/techdocs-backend/src/cache/TechDocsCache.test.ts @@ -162,9 +162,7 @@ describe('TechDocsCache', () => { await expect( CacheUnderTest.invalidateMultiple.bind(CacheUnderTest, expectedPaths), - ).rejects.toThrow( - expect.objectContaining({ rejections: expect.arrayContaining([]) }), - ); + ).rejects.toThrow(CacheInvalidationError); }); }); }); diff --git a/plugins/techdocs-backend/src/cache/TechDocsCache.ts b/plugins/techdocs-backend/src/cache/TechDocsCache.ts index b12142dda5..147aed0a18 100644 --- a/plugins/techdocs-backend/src/cache/TechDocsCache.ts +++ b/plugins/techdocs-backend/src/cache/TechDocsCache.ts @@ -14,18 +14,11 @@ * limitations under the License. */ import { CacheClient } from '@backstage/backend-common'; -import { assertError } from '@backstage/errors'; +import { assertError, CustomErrorBase } from '@backstage/errors'; import { Config } from '@backstage/config'; import { Logger } from 'winston'; -export class CacheInvalidationError extends Error { - public readonly rejections: PromiseRejectedResult[]; - - constructor(rejections: PromiseRejectedResult[]) { - super(); - this.rejections = rejections; - } -} +export class CacheInvalidationError extends CustomErrorBase {} export class TechDocsCache { protected readonly cache: CacheClient; @@ -101,7 +94,10 @@ export class TechDocsCache { ) as PromiseRejectedResult[]; if (rejected.length) { - throw new CacheInvalidationError(rejected); + throw new CacheInvalidationError( + 'TechDocs cache invalidation error', + rejected, + ); } return settled; diff --git a/plugins/techdocs-backend/src/cache/cacheMiddleware.ts b/plugins/techdocs-backend/src/cache/cacheMiddleware.ts index 66471b0189..9e545c235c 100644 --- a/plugins/techdocs-backend/src/cache/cacheMiddleware.ts +++ b/plugins/techdocs-backend/src/cache/cacheMiddleware.ts @@ -16,7 +16,7 @@ import { Router } from 'express'; import router from 'express-promise-router'; import { Logger } from 'winston'; -import { TechDocsCache } from '.'; +import { TechDocsCache } from './TechDocsCache'; type CacheMiddlewareOptions = { cache: TechDocsCache; @@ -69,7 +69,7 @@ export const createCacheMiddleware = ({ socket.on('close', hadError => { const content = Buffer.concat(chunks); const head = content.toString('utf8', 0, 12); - if (writeToCache && !hadError && head === 'HTTP/1.1 200') { + if (writeToCache && !hadError && head.match(/HTTP\/\d\.\d 200/)) { cache.set(reqPath, content); } });