github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/thirdparty/api_models.go (about)

     1  package thirdparty
     2  
     3  import "fmt"
     4  
     5  // Infrastructure/communication-related errors
     6  
     7  type ResponseReadError struct {
     8  	msg string
     9  }
    10  
    11  func (re ResponseReadError) Error() string {
    12  	return fmt.Sprintf("API response read error: %v", re.msg)
    13  }
    14  
    15  type APIUnmarshalError struct {
    16  	body, msg string
    17  }
    18  
    19  func (ue APIUnmarshalError) Error() string {
    20  	return fmt.Sprintf("API response unmarshal error on %v: %v",
    21  		ue.body, ue.msg)
    22  }
    23  
    24  type APIResponseError struct {
    25  	msg string
    26  }
    27  
    28  func (are APIResponseError) Error() string {
    29  	return fmt.Sprintf("API response error: %v", are.msg)
    30  }
    31  
    32  // Configuration-related errors
    33  
    34  // This error should be returned when the requested remote configuration file
    35  // can not be found.
    36  type FileNotFoundError struct {
    37  	filepath string
    38  }
    39  
    40  func (nfe FileNotFoundError) Error() string {
    41  	return fmt.Sprintf("Requested file at %v not found", nfe.filepath)
    42  }
    43  
    44  func IsFileNotFound(err error) bool {
    45  	_, ok := err.(FileNotFoundError)
    46  	return ok
    47  }
    48  
    49  type FileDecodeError struct {
    50  	Message string
    51  }
    52  
    53  func (f FileDecodeError) Error() string {
    54  	return fmt.Sprintf("file decoding failed: %v", f.Message)
    55  }
    56  
    57  type YAMLFormatError struct {
    58  	Message string
    59  }
    60  
    61  func (y YAMLFormatError) Error() string {
    62  	return fmt.Sprintf("invalid configuration file: %v", y.Message)
    63  }
    64  
    65  // When attempting to access the some API using authentication, requests may
    66  // return 404 Not Found, instead of 403 Forbidden, under certain circumstances.
    67  // For example, see https://developer.github.com/v3/#authentication.
    68  // This struct should be used for errors in fetching a requested remote config.
    69  type APIRequestError struct {
    70  	Message          string `json:"message"`
    71  	DocumentationUrl string `json:"documentation_url"`
    72  }
    73  
    74  func (are APIRequestError) Error() string {
    75  	return fmt.Sprintf("API request error: %v", are.Message)
    76  }