Skip to content

Commit

Permalink
Use ConfigureationError for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogario committed Jan 27, 2025
1 parent f6d19ed commit 7c2eafa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/start-proxy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/start-proxy.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/start-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseLanguage, Language } from "./languages";
import { Logger } from "./logging";
import { ConfigurationError } from "./util";

export type Credential = {
type: string;
Expand Down Expand Up @@ -57,14 +58,16 @@ export function getCredentials(
} catch {
// Don't log the error since it might contain sensitive information.
logger.error("Failed to parse the credentials data.");
throw new Error("Invalid credentials format.");
throw new ConfigurationError("Invalid credentials format.");
}

const out: Credential[] = [];
for (const e of parsed) {
if (e.url === undefined && e.host === undefined) {
// The proxy needs one of these to work. If both are defined, the url has the precedence.
throw new Error("Invalid credentials - must specify host or url");
throw new ConfigurationError(
"Invalid credentials - must specify host or url",
);
}

// Filter credentials based on language if specified. `type` is the registry type.
Expand All @@ -85,7 +88,7 @@ export function getCredentials(
!isPrintable(e.password) ||
!isPrintable(e.token)
) {
throw new Error(
throw new ConfigurationError(
"Invalid credentials - fields must contain only printable characters",
);
}
Expand Down

0 comments on commit 7c2eafa

Please sign in to comment.