Skip to content

Commit

Permalink
better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
platinummonkey committed Jul 17, 2019
1 parent 6936511 commit 5f045d6
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 14 deletions.
93 changes: 93 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13964,6 +13964,99 @@ func (s *ServiceLevelObjective) SetTypeID(v int) {
s.TypeID = &v
}

// GetID returns the ID field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetID() string {
if s == nil || s.ID == nil {
return ""
}
return *s.ID
}

// GetIDOk returns a tuple with the ID field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetIDOk() (string, bool) {
if s == nil || s.ID == nil {
return "", false
}
return *s.ID, true
}

// HasID returns a boolean if a field has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasID() bool {
if s != nil && s.ID != nil {
return true
}

return false
}

// SetID allocates a new s.ID and returns the pointer to it.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetID(v string) {
s.ID = &v
}

// GetMessage returns the Message field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetMessage() string {
if s == nil || s.Message == nil {
return ""
}
return *s.Message
}

// GetMessageOk returns a tuple with the Message field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetMessageOk() (string, bool) {
if s == nil || s.Message == nil {
return "", false
}
return *s.Message, true
}

// HasMessage returns a boolean if a field has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasMessage() bool {
if s != nil && s.Message != nil {
return true
}

return false
}

// SetMessage allocates a new s.Message and returns the pointer to it.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetMessage(v string) {
s.Message = &v
}

// GetTimeFrame returns the TimeFrame field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetTimeFrame() string {
if s == nil || s.TimeFrame == nil {
return ""
}
return *s.TimeFrame
}

// GetTimeFrameOk returns a tuple with the TimeFrame field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetTimeFrameOk() (string, bool) {
if s == nil || s.TimeFrame == nil {
return "", false
}
return *s.TimeFrame, true
}

// HasTimeFrame returns a boolean if a field has been set.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasTimeFrame() bool {
if s != nil && s.TimeFrame != nil {
return true
}

return false
}

// SetTimeFrame allocates a new s.TimeFrame and returns the pointer to it.
func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetTimeFrame(v string) {
s.TimeFrame = &v
}

// GetDenominator returns the Denominator field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveMetricQuery) GetDenominator() string {
if s == nil || s.Denominator == nil {
Expand Down
52 changes: 39 additions & 13 deletions service_level_objectives.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package datadog

import (
"encoding/json"
"fmt"
"net/url"
"strings"
Expand Down Expand Up @@ -49,16 +48,33 @@ type ServiceLevelObjectiveMetricQuery struct {
Denominator *string `json:"denominator,omitempty"`
}

type ServiceLevelObjectiveThresholds []*ServiceLevelObjectiveThreshold

// Len implements sort.Interface length
func (t ServiceLevelObjectiveThresholds) Len() int {
return len(t)
}

// Less implements sort.Interface less comparator
func (t ServiceLevelObjectiveThresholds) Less(i, j int) bool {
return strings.Compare(t[i].GetTimeFrame(), t[j].GetTimeFrame()) == -1
}

// Swap implements sort.Interface swap method
func (t ServiceLevelObjectiveThresholds) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
}

// ServiceLevelObjective defines the Service Level Objective entity
type ServiceLevelObjective struct {
// Common
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Thresholds []*ServiceLevelObjectiveThreshold `json:"thresholds,omitempty"`
Type *string `json:"type,omitempty"`
TypeID *int `json:"type_id,omitempty"` // Read-Only
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
Thresholds ServiceLevelObjectiveThresholds `json:"thresholds,omitempty"`
Type *string `json:"type,omitempty"`
TypeID *int `json:"type_id,omitempty"` // Read-Only
// SLI definition
Query *ServiceLevelObjectiveMetricQuery `json:"query,omitempty"`
MonitorIDs []int `json:"monitor_ids,omitempty"`
Expand Down Expand Up @@ -253,9 +269,22 @@ type ServiceLevelObjectiveDeleteTimeFramesResponse struct {
UpdatedIDs []string `json:"updated"`
}

// ServiceLevelObjectiveDeleteTimeFramesError is the error specific to deleting individual time frames.
// It contains more detailed information than the standard error.
type ServiceLevelObjectiveDeleteTimeFramesError struct {
ID *string `json:"id"`
TimeFrame *string `json:"timeframe"`
Message *string `json:"message"`
}

// Error computes the human readable error
func (e ServiceLevelObjectiveDeleteTimeFramesError) Error() string {
return fmt.Sprintf("error=%s id=%s for timeframe=%s", e.GetMessage(), e.GetID(), e.GetTimeFrame())
}

type timeframesDeleteResp struct {
Data *ServiceLevelObjectiveDeleteTimeFramesResponse `json:"data"`
Errors []map[string]interface{} `json:"errors"`
Errors []*ServiceLevelObjectiveDeleteTimeFramesError `json:"errors"`
}

// DeleteServiceLevelObjectiveTimeFrames will delete SLO timeframes individually.
Expand All @@ -275,10 +304,7 @@ func (client *Client) DeleteServiceLevelObjectiveTimeFrames(timeframeByID map[st
if out.Errors != nil && len(out.Errors) > 0 {
errMsgs := make([]string, 0)
for _, e := range out.Errors {
if len(e) > 0 {
b, _ := json.Marshal(e)
errMsgs = append(errMsgs, string(b))
}
errMsgs = append(errMsgs, e.Error())
}
return nil, fmt.Errorf("errors deleting timeframes: %s", strings.Join(errMsgs, ","))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"deleted": ["abcdefabcdefabcdefabcdefabcdefab"],
"updated": ["12345678901234567890123456789012"]
},
"error": null
"errors": null
}

0 comments on commit 5f045d6

Please sign in to comment.