Unwrap error message when getting projects in Jenkins plugin

Signed-off-by: Tim Jacomb <timjacomb1@gmail.com>
This commit is contained in:
Tim Jacomb
2022-09-16 10:47:29 +01:00
parent 535ca54f0e
commit a966ed8385
3 changed files with 22 additions and 5 deletions
@@ -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, ''),
});
+16 -4
View File
@@ -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,22 @@ 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
}
},
);