Add info about which proxy-backend target isn't well configured.

Signed-off-by: Christoph Jerolimov <jerolimov+github@redhat.com>
This commit is contained in:
Christoph Jerolimov
2023-09-04 11:00:50 +02:00
parent f59215f451
commit 02ba0a2efd
3 changed files with 18 additions and 4 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@backstage/plugin-proxy-backend': patch
---
Add the route name to an error message that appears when the backend
proxy wasn't well configured. This will help users to understand the
issue and fix the right configuration.
@@ -157,7 +157,11 @@ describe('createRouter', () => {
logger,
discovery,
}),
).rejects.toThrow(new Error('Proxy target must be a string'));
).rejects.toThrow(
new Error(
'Proxy target for route "/test" must be a string, but is of type undefined',
),
);
});
it('works if skip failures is set', async () => {
@@ -189,7 +193,7 @@ describe('createRouter', () => {
skipInvalidProxies: true,
});
expect((logger.warn as jest.Mock).mock.calls[0][0]).toEqual(
'skipped configuring /test due to Proxy target must be a string',
'skipped configuring /test due to Proxy target for route "/test" must be a string, but is of type undefined',
);
expect(router).toBeDefined();
});
+5 -2
View File
@@ -76,8 +76,11 @@ export function buildMiddleware(
typeof config === 'string' ? { target: config } : { ...config };
// Validate that target is a valid URL.
if (typeof fullConfig.target !== 'string') {
throw new Error(`Proxy target must be a string`);
const targetType = typeof fullConfig.target;
if (targetType !== 'string') {
throw new Error(
`Proxy target for route "${route}" must be a string, but is of type ${targetType}`,
);
}
try {
// eslint-disable-next-line no-new