Review feedback.

Signed-off-by: Eric Peterson <i.am@eric.pe>
This commit is contained in:
Eric Peterson
2021-11-28 13:33:11 -07:00
parent e0930f578e
commit 6e9e82b99d
4 changed files with 12 additions and 16 deletions
@@ -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,
};
}
+1 -3
View File
@@ -162,9 +162,7 @@ describe('TechDocsCache', () => {
await expect(
CacheUnderTest.invalidateMultiple.bind(CacheUnderTest, expectedPaths),
).rejects.toThrow(
expect.objectContaining({ rejections: expect.arrayContaining([]) }),
);
).rejects.toThrow(CacheInvalidationError);
});
});
});
+6 -10
View File
@@ -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;
+2 -2
View File
@@ -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);
}
});