@@ -235,6 +235,10 @@ func (s *Client) Put(urlPath string, payload interface{}) ([]byte, error) {
235235}
236236
237237func (s * Client ) Get (urlPath string ) ([]byte , string , error ) {
238+ return s .GetWithErrOpt (urlPath , false )
239+ }
240+
241+ func (s * Client ) GetWithErrOpt (urlPath string , return404Err bool ) ([]byte , string , error ) {
238242 relativeURL , _ := url .Parse (urlPath )
239243 sumoURL := s .BaseURL .ResolveReference (relativeURL )
240244
@@ -260,7 +264,11 @@ func (s *Client) Get(urlPath string) ([]byte, string, error) {
260264 }
261265
262266 if resp .StatusCode == 404 {
263- return nil , "" , nil
267+ if return404Err {
268+ return nil , "" , errors .New (string (d ))
269+ } else {
270+ return nil , "" , nil
271+ }
264272 } else if resp .StatusCode >= 400 {
265273 return nil , "" , errors .New (string (d ))
266274 }
@@ -341,19 +349,21 @@ func NewClient(accessID, accessKey, authJwt, environment, base_url string, admin
341349 return & client , nil
342350}
343351
344- func HasErrorCode (errorJsonStr string , errorCode string ) bool {
352+ func HasErrorCode (errorJsonStr string , errorCodeChoices [] string ) string {
345353 var apiError ApiError
346354 jsonErr := json .Unmarshal ([]byte (errorJsonStr ), & apiError )
347355 if jsonErr != nil {
348356 // when fail to unmarshal JSON, we should consider the errorCode is not found
349- return false
357+ return ""
350358 }
351359 for i := range apiError .Errors {
352- if apiError .Errors [i ].Code == errorCode {
353- return true
360+ for j := range errorCodeChoices {
361+ if apiError .Errors [i ].Code == errorCodeChoices [j ] {
362+ return errorCodeChoices [j ]
363+ }
354364 }
355365 }
356- return false
366+ return ""
357367}
358368
359369type Error struct {
@@ -362,7 +372,9 @@ type Error struct {
362372 Detail string `json:"detail"`
363373}
364374
365- // e.g. {"id":"8UQOI-82VTR-YBQ8G","errors":[{"code":"not_implemented_yet","message":"Not implemented yet"}]}
375+ // e.g.:
376+ // {"id":"8UQOI-82VTR-YBQ8G","errors":[{"code":"not_implemented_yet","message":"Not implemented yet"}]}
377+ // {"id":"RO4X1-BZW7P-Q8KJF","errors":[{"code":"api_not_enabled","message":"This API is not enabled for your organization."}]}
366378type ApiError struct {
367379 Id string `json:"id"`
368380 Errors []Error `json:"errors"`
0 commit comments