Merge pull request #13700 from timja/additional-error-handling
Unwrap error message when getting projects in Jenkins plugin
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-jenkins-backend': patch
|
||||
---
|
||||
|
||||
Unwrap error message when getting projects
|
||||
@@ -100,7 +100,7 @@ export class JenkinsApiImpl {
|
||||
// Filter only be the information we need, instead of loading all fields.
|
||||
// Limit to only show the latest build for each job and only load 50 jobs
|
||||
// at all.
|
||||
// Whitespaces are only included for readablity here and stripped out
|
||||
// Whitespaces are only included for readability here and stripped out
|
||||
// before sending to Jenkins
|
||||
tree: JenkinsApiImpl.jobsTreeSpec.replace(/\s/g, ''),
|
||||
});
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from '@backstage/plugin-permission-common';
|
||||
import { getBearerTokenFromAuthorizationHeader } from '@backstage/plugin-auth-node';
|
||||
import { stringifyEntityRef } from '@backstage/catalog-model';
|
||||
import { stringifyError } from '@backstage/errors';
|
||||
|
||||
/** @public */
|
||||
export interface RouterOptions {
|
||||
@@ -90,11 +91,25 @@ export async function createRouter(
|
||||
},
|
||||
backstageToken: token,
|
||||
});
|
||||
const projects = await jenkinsApi.getProjects(jenkinsInfo, branches);
|
||||
|
||||
response.json({
|
||||
projects: projects,
|
||||
});
|
||||
try {
|
||||
const projects = await jenkinsApi.getProjects(jenkinsInfo, branches);
|
||||
|
||||
response.json({
|
||||
projects: projects,
|
||||
});
|
||||
} catch (err) {
|
||||
// Promise.any, used in the getProjects call returns an Aggregate error message with a useless error message 'AggregateError: All promises were rejected'
|
||||
// extract useful information ourselves
|
||||
if (err.errors) {
|
||||
throw new Error(
|
||||
`Unable to fetch projects, for ${
|
||||
jenkinsInfo.jobFullName
|
||||
}: ${stringifyError(err.errors)}`,
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user