github.com/pivotal-cf/go-pivnet/v6@v6.0.2/errors.go (about)

     1  package pivnet
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"strings"
     7  )
     8  
     9  type pivnetErr struct {
    10  	Message string   `json:"message"`
    11  	Errors  []string `json:"errors"`
    12  }
    13  
    14  type pivnetInternalServerErr struct {
    15  	Error string `json:"error"`
    16  }
    17  
    18  type ErrPivnetOther struct {
    19  	ResponseCode int      `json:"response_code" yaml:"response_code"`
    20  	Message      string   `json:"message" yaml:"message"`
    21  	Errors       []string `json:"errors" yaml:"errors"`
    22  }
    23  
    24  func (e ErrPivnetOther) Error() string {
    25  	return fmt.Sprintf(
    26  		"%d - %s. Errors: %v",
    27  		e.ResponseCode,
    28  		e.Message,
    29  		strings.Join(e.Errors, ","),
    30  	)
    31  }
    32  
    33  type ErrUnauthorized struct {
    34  	ResponseCode int    `json:"response_code" yaml:"response_code"`
    35  	Message      string `json:"message" yaml:"message"`
    36  }
    37  
    38  func (e ErrUnauthorized) Error() string {
    39  	return e.Message
    40  }
    41  
    42  func newErrUnauthorized(message string) ErrUnauthorized {
    43  	return ErrUnauthorized{
    44  		ResponseCode: http.StatusUnauthorized,
    45  		Message:      message,
    46  	}
    47  }
    48  
    49  type ErrNotFound struct {
    50  	ResponseCode int    `json:"response_code" yaml:"response_code"`
    51  	Message      string `json:"message" yaml:"message"`
    52  }
    53  
    54  func (e ErrNotFound) Error() string {
    55  	return e.Message
    56  }
    57  
    58  func newErrNotFound(message string) ErrNotFound {
    59  	return ErrNotFound{
    60  		ResponseCode: http.StatusNotFound,
    61  		Message:      message,
    62  	}
    63  }
    64  
    65  type ErrUnavailableForLegalReasons struct {
    66  	ResponseCode int    `json:"response_code" yaml:"response_code"`
    67  	Message      string `json:"message" yaml:"message"`
    68  }
    69  
    70  func (e ErrUnavailableForLegalReasons) Error() string {
    71  	return e.Message
    72  }
    73  
    74  func newErrUnavailableForLegalReasons(message string) ErrUnavailableForLegalReasons {
    75  	return ErrUnavailableForLegalReasons{
    76  		ResponseCode: http.StatusUnavailableForLegalReasons,
    77  		Message:      message,
    78  	}
    79  }
    80  
    81  type ErrTooManyRequests struct {
    82  	ResponseCode int    `json:"response_code" yaml:"response_code"`
    83  	Message      string `json:"message" yaml:"message"`
    84  }
    85  
    86  func (e ErrTooManyRequests) Error() string {
    87  	return e.Message
    88  }
    89  
    90  func newErrTooManyRequests() ErrTooManyRequests {
    91  	return ErrTooManyRequests{
    92  		ResponseCode: http.StatusTooManyRequests,
    93  		Message: "You have hit a rate limit for this request",
    94  	}
    95  }