github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccerror/v3_unexpected_response_error.go (about)

     1  package ccerror
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  // V3ErrorResponse represents a generic Cloud Controller V3 error response.
     9  type V3ErrorResponse struct {
    10  	Errors []V3Error `json:"errors"`
    11  }
    12  
    13  // V3Error represents a cloud controller error.
    14  type V3Error struct {
    15  	Code   int    `json:"code"`
    16  	Detail string `json:"detail"`
    17  	Title  string `json:"title"`
    18  }
    19  
    20  // V3UnexpectedResponseError is returned when the client gets an error that has
    21  // not been accounted for.
    22  type V3UnexpectedResponseError struct {
    23  	V3ErrorResponse
    24  
    25  	ResponseCode int
    26  	RequestIDs   []string
    27  }
    28  
    29  func (e V3UnexpectedResponseError) Error() string {
    30  	messages := []string{
    31  		"Unexpected Response",
    32  		fmt.Sprintf("Response Code: %d", e.ResponseCode),
    33  	}
    34  
    35  	for _, id := range e.RequestIDs {
    36  		messages = append(messages, fmt.Sprintf("Request ID:    %s", id))
    37  	}
    38  
    39  	for _, ccError := range e.V3ErrorResponse.Errors {
    40  		messages = append(messages, fmt.Sprintf("Code: %d, Title: %s, Detail: %s", ccError.Code, ccError.Title, ccError.Detail))
    41  	}
    42  
    43  	return strings.Join(messages, "\n")
    44  }