github.com/twilio/twilio-go@v1.20.1/client/error.go (about)

     1  // Package error provides the interface for Twilio specific errors.
     2  package client
     3  
     4  import (
     5  	"encoding/json"
     6  	"fmt"
     7  )
     8  
     9  // TwilioRestError provides information about an unsuccessful request.
    10  type TwilioRestError struct {
    11  	Code     int                    `json:"code"`
    12  	Details  map[string]interface{} `json:"details"`
    13  	Message  string                 `json:"message"`
    14  	MoreInfo string                 `json:"more_info"`
    15  	Status   int                    `json:"status"`
    16  }
    17  
    18  func (err *TwilioRestError) Error() string {
    19  	detailsJSON, _ := json.Marshal(err.Details)
    20  	return fmt.Sprintf("Status: %d - ApiError %d: %s (%s) More info: %s",
    21  		err.Status, err.Code, err.Message, detailsJSON, err.MoreInfo)
    22  }