Help us shape the future of Go! Take the 2026 Go Developer Survey

apierror

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package apierror renders errors in the envelope each client surface expects. Artifactory, Access, the OCI distribution API, Xray, npm and the Terraform registry all use different JSON shapes, and clients read them differently: jfrog-client-go prints the whole body after the status (only its release bundle import reads errors[0].message, and its Xray scan reads error), the Terraform providers join every errors[] entry, and Docker clients read errors[].code. One table here is the only place a shape is defined. See decision record 0002.

Index

Constants

View Source
const BasicChallenge = `Basic realm="Artifactory Realm"`

BasicChallenge is the WWW-Authenticate value of a 401: Artifactory's realm.

Variables

View Source
var ErrNotImplemented = &Error{
	Status:  http.StatusNotImplemented,
	Code:    "NOT_IMPLEMENTED",
	Message: "not implemented by artifactweave yet",
}

ErrNotImplemented is returned by generated UnimplementedStrict stubs for operations the spec declares but no service implements yet. The strict response error handler renders it as 501 in the surface's envelope, so a scaffolded operation is visibly absent rather than a 500.

Functions

func Write

func Write(w http.ResponseWriter, s Surface, err error)

Write renders err on the given surface. Errors that are not *Error become a 500 with a generic message so internal details never reach a client.

Types

type Error

type Error struct {
	Status  int
	Code    string
	Message string
	Detail  any
}

Error carries everything needed to render on any surface. Code is the OCI or Access symbolic code; Artifactory ignores it and uses Status.

func New

func New(status int, message string) *Error

New builds an Error for a status with a message.

func NotSupported

func NotSupported(product string) *Error

NotSupported is the 501 answer for stubbed JFrog products. The message names artifactweave so operators reading a Terraform or jf error know the product is absent rather than broken.

func (*Error) Error

func (e *Error) Error() string

type Surface

type Surface int

Surface selects the error envelope. The zero value is Artifactory, which is the right default for anything under /artifactory.

const (
	// Artifactory is {"errors":[{"status":404,"message":"..."}]}.
	Artifactory Surface = iota
	// Access is {"errors":[{"code":"NOT_FOUND","message":"..."}]}, used by
	// /access and the Projects API.
	Access
	// OCI is {"errors":[{"code":"BLOB_UNKNOWN","message":"...","detail":...}]}.
	OCI
	// Xray is {"error":"..."}; served only by the 501 stubs.
	Xray
	// NPM is {"error":"..."}; npm prints the field verbatim.
	NPM
	// TerraformRegistry is {"errors":["..."]}.
	TerraformRegistry
	// Distribution is {"status_code":404,"message":"...","errors":[{"status":404,"message":"..."}]},
	// the shape JFrog Distribution documents; detail is added when set.
	Distribution
	// ArtifactoryLegacy is the Artifactory envelope plus top-level error and
	// message, documented for cold storage retention:
	// {"errors":[{"status":400,"message":"..."}],"error":"Bad Request","message":"..."}.
	ArtifactoryLegacy
	// ImportExport is the Artifactory envelope plus a top-level error that
	// carries the message, documented for import and export:
	// {"errors":[{"status":400,"message":"..."}],"error":"..."}.
	ImportExport
	// PlatformFederation is {"code":404,"message":"..."}, the HTTP status as
	// an integer code, used by the platform federation service (/pfed).
	PlatformFederation
	// Grid is {"code":"NOT_FOUND","message":"..."}, a symbolic code, with
	// details when set, used by the topology service (/grid).
	Grid
	// Text is a plain-text body, used by the Go proxy, PyPI and NuGet where
	// clients do not parse JSON errors.
	Text
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL