π§° Helpers and errors
Token redaction, formatters and the typed errors the core throws.
Redaction
The token never appears in errors the core raises. For your own logging:
import { redactConfig, redactToken } from "@kud/sonarqube"
console.log(redactConfig(config))
console.log(redactToken(someText, config.token))| Function | Behaviour |
|---|---|
redactConfig(config) | Copy of the config with token replaced by *** |
redactToken(text, token?) | Replaces every occurrence of the token in text |
Formatters
| Function | Behaviour |
|---|---|
formatIssueAuthor(author?) | The part before the @, or an empty string |
formatDate(value?) | YYYY-MM-DD from a SonarQube timestamp, or an empty string when unparseable |
Errors
| Error | Thrown when |
|---|---|
MissingHostError | A client is constructed without a host |
SonarQubeAuthError | The server answers 401; a subclass of SonarQubeHttpError whose message names the env var the token came from when it is known |
SonarQubeHttpError | The server answers with a non-2xx status; exposes status and path |
import { SonarQubeAuthError, SonarQubeHttpError } from "@kud/sonarqube"
try {
await client.getIssues({ project: "acme-api" })
} catch (err) {
if (err instanceof SonarQubeAuthError) {
// token missing or rejected
} else if (err instanceof SonarQubeHttpError) {
// other server error
}
throw err
}Types
All query and result shapes (IssuesQuery, IssuesResult, GateExplanation, Hotspot, Rule, ComponentTree and the rest) are exported from the package root.