Merge pull request #4308 from backstage/orkohunter/better-error-when-apiBaseUrl-is-missing

backend: Gitlab URL Reader to throw error when apiBaseUrl is missing
This commit is contained in:
Himanshu Mishra
2021-02-01 11:18:04 +01:00
committed by GitHub
4 changed files with 45 additions and 0 deletions
@@ -242,5 +242,17 @@ describe('BitbucketUrlReader', () => {
expect(response.etag).toBe('12ab34cd56ef');
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new BitbucketUrlReader(
{
host: 'bitbucket.mycompany.net',
},
{ treeResponseFactory },
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -376,5 +376,20 @@ describe('GithubUrlReader', () => {
};
await expect(fnGithub).rejects.toThrow(NotFoundError);
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new GithubUrlReader(
{
host: 'ghe.mycompany.net',
},
{
treeResponseFactory,
credentialsProvider: mockCredentialsProvider,
},
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -379,5 +379,17 @@ describe('GitlabUrlReader', () => {
};
await expect(fnGithub).rejects.toThrow(NotFoundError);
});
it('should throw error when apiBaseUrl is missing', () => {
expect(() => {
/* eslint-disable no-new */
new GitlabUrlReader(
{
host: 'gitlab.mycompany.com',
},
{ treeResponseFactory },
);
}).toThrowError('must configure an explicit apiBaseUrl');
});
});
});
@@ -51,6 +51,12 @@ export class GitlabUrlReader implements UrlReader {
deps: { treeResponseFactory: ReadTreeResponseFactory },
) {
this.treeResponseFactory = deps.treeResponseFactory;
if (!config.apiBaseUrl) {
throw new Error(
`GitLab integration for '${config.host}' must configure an explicit apiBaseUrl`,
);
}
}
async read(url: string): Promise<Buffer> {