github.com/CiscoM31/godata@v1.0.10/errors.go (about)

     1  package godata
     2  
     3  import "fmt"
     4  
     5  type GoDataError struct {
     6  	ResponseCode int
     7  	Message      string
     8  	Cause        error
     9  }
    10  
    11  func (err *GoDataError) Error() string {
    12  	if err.Cause != nil {
    13  		return fmt.Sprintf("%s. Cause: %s", err.Message, err.Cause.Error())
    14  	}
    15  	return err.Message
    16  }
    17  
    18  func (err *GoDataError) Unwrap() error {
    19  	return err.Cause
    20  }
    21  
    22  func (err *GoDataError) SetCause(e error) *GoDataError {
    23  	err.Cause = e
    24  	return err
    25  }
    26  
    27  func BadRequestError(message string) *GoDataError {
    28  	return &GoDataError{400, message, nil}
    29  }
    30  
    31  func NotFoundError(message string) *GoDataError {
    32  	return &GoDataError{404, message, nil}
    33  }
    34  
    35  func MethodNotAllowedError(message string) *GoDataError {
    36  	return &GoDataError{405, message, nil}
    37  }
    38  
    39  func GoneError(message string) *GoDataError {
    40  	return &GoDataError{410, message, nil}
    41  }
    42  
    43  func PreconditionFailedError(message string) *GoDataError {
    44  	return &GoDataError{412, message, nil}
    45  }
    46  
    47  func InternalServerError(message string) *GoDataError {
    48  	return &GoDataError{500, message, nil}
    49  }
    50  
    51  func NotImplementedError(message string) *GoDataError {
    52  	return &GoDataError{501, message, nil}
    53  }
    54  
    55  type UnsupportedQueryParameterError struct {
    56  	Parameter string
    57  }
    58  
    59  func (err *UnsupportedQueryParameterError) Error() string {
    60  	return fmt.Sprintf("Query parameter '%s' is not supported", err.Parameter)
    61  }
    62  
    63  type DuplicateQueryParameterError struct {
    64  	Parameter string
    65  }
    66  
    67  func (err *DuplicateQueryParameterError) Error() string {
    68  	return fmt.Sprintf("Query parameter '%s' cannot be specified more than once", err.Parameter)
    69  }