Skip to Content
sonarqube

🧰 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))
FunctionBehaviour
redactConfig(config)Copy of the config with token replaced by ***
redactToken(text, token?)Replaces every occurrence of the token in text

Formatters

FunctionBehaviour
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

ErrorThrown when
MissingHostErrorA client is constructed without a host
SonarQubeAuthErrorThe server answers 401; a subclass of SonarQubeHttpError whose message names the env var the token came from when it is known
SonarQubeHttpErrorThe 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.