@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user