response.go raw

   1  package goinwx
   2  
   3  import "fmt"
   4  
   5  // Response is a INWX API response. This wraps the standard http.Response returned from INWX.
   6  type Response struct {
   7  	Code         int            `xmlrpc:"code"`
   8  	Message      string         `xmlrpc:"msg"`
   9  	ReasonCode   string         `xmlrpc:"reasonCode"`
  10  	Reason       string         `xmlrpc:"reason"`
  11  	ResponseData map[string]any `xmlrpc:"resData"`
  12  }
  13  
  14  // An ErrorResponse reports the error caused by an API request.
  15  type ErrorResponse struct {
  16  	Code       int    `xmlrpc:"code"`
  17  	Message    string `xmlrpc:"msg"`
  18  	ReasonCode string `xmlrpc:"reasonCode"`
  19  	Reason     string `xmlrpc:"reason"`
  20  }
  21  
  22  func (r *ErrorResponse) Error() string {
  23  	if r.Reason != "" {
  24  		return fmt.Sprintf("(%d) %s. Reason: (%s) %s",
  25  			r.Code, r.Message, r.ReasonCode, r.Reason)
  26  	}
  27  
  28  	return fmt.Sprintf("(%d) %s", r.Code, r.Message)
  29  }
  30