diff --git a/.changeset/dirty-boxes-give.md b/.changeset/dirty-boxes-give.md new file mode 100644 index 0000000000..d339e49c98 --- /dev/null +++ b/.changeset/dirty-boxes-give.md @@ -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. diff --git a/plugins/proxy-backend/src/service/router.test.ts b/plugins/proxy-backend/src/service/router.test.ts index 2b58e52e94..23b6e17ecc 100644 --- a/plugins/proxy-backend/src/service/router.test.ts +++ b/plugins/proxy-backend/src/service/router.test.ts @@ -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(); }); diff --git a/plugins/proxy-backend/src/service/router.ts b/plugins/proxy-backend/src/service/router.ts index 61fddb60ed..96b9beceee 100644 --- a/plugins/proxy-backend/src/service/router.ts +++ b/plugins/proxy-backend/src/service/router.ts @@ -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