...

Package errors

import "github.com/go-kivik/kivik/v4/int/errors"
Overview
Index

Overview ▾

Package errors provides some internal error types and utilities.

func HTTPStatus

func HTTPStatus(err error) int

HTTPStatus returns the HTTP status code embedded in the error, or 500 (internal server error), if there was no specified status code. If err is nil, HTTPStatus returns 0.

func StatusErrorDiff

func StatusErrorDiff(wantErr string, wantStatus int, err error) string

StatusErrorDiff returns the empty string if the expected error string and status match err. Otherwise, it returns a description of the mismatch.

func StatusErrorDiffRE

func StatusErrorDiffRE(wantErrRE string, wantStatus int, err error) string

StatusErrorDiffRE returns the empty string if the expected error RE and status match err. Otherwise, it returns a description of the mismatch.

type CompositeError

CompositeError represents an HTTP status, encoded in the first byte as the status - 400, plus the error message.

type CompositeError string

func (CompositeError) Error

func (c CompositeError) Error() string

func (CompositeError) HTTPStatus

func (c CompositeError) HTTPStatus() int

HTTPStatus returns c's HTTP status code.

type Error

Error represents an error returned by Kivik.

This type definition is not guaranteed to remain stable, or even exported. When examining errors programmatically, you should rely instead on the HTTPStatus() function in this package, rather than on directly observing the fields of this type.

type Error struct {
    // Status is the HTTP status code associated with this error. Normally
    // this is the actual HTTP status returned by the server, but in some cases
    // it may be generated by Kivik directly.
    Status int

    // Message is the error message.
    Message string

    // Err is the originating error, if any.
    Err error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(f fmt.State, c rune)

Format implements fmt.Formatter.

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

HTTPStatus returns the HTTP status code associated with the error, or 500 (internal server error), if none.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap satisfies the errors wrapper interface.