Skip to content

Commit

Permalink
Improve monitoring endpoint validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Aug 14, 2023
1 parent 51382d0 commit 4fddfda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/monitoring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class MonitoringService {

private parseMonitoringEndpoint(endpoint: string): URL {
if (!endpoint) {
throw new Error("Monitoring endpoint must be provided");
throw new Error(`Monitoring endpoint is empty or undefined: ${endpoint}`);
}

try {
Expand All @@ -226,7 +226,7 @@ export class MonitoringService {

return url;
} catch {
throw new Error("Monitoring endpoint must be a valid URL");
throw new Error(`Monitoring endpoint must be a valid URL: ${endpoint}`);
}
}
}
10 changes: 6 additions & 4 deletions packages/beacon-node/test/unit/monitoring/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ describe("monitoring / service", () => {
});

it("should throw an error if monitoring endpoint is not provided", () => {
expect(() => new MonitoringService("beacon", {endpoint: ""}, {register, logger})).to.throw(
"Monitoring endpoint must be provided"
const endpoint = "";
expect(() => new MonitoringService("beacon", {endpoint}, {register, logger})).to.throw(
`Monitoring endpoint is empty or undefined: ${endpoint}`
);
});

it("should throw an error if monitoring endpoint is not a valid URL", () => {
expect(() => new MonitoringService("beacon", {endpoint: "invalid"}, {register, logger})).to.throw(
"Monitoring endpoint must be a valid URL"
const endpoint = "invalid";
expect(() => new MonitoringService("beacon", {endpoint}, {register, logger})).to.throw(
`Monitoring endpoint must be a valid URL: ${endpoint}`
);
});

Expand Down

0 comments on commit 4fddfda

Please sign in to comment.