Skip to content

Error handling #579

Closed Answered by kecci
BigBoulard asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @BigBoulard,

Disclaimer: I would answer this from my project experienced before

There is 3 layer validation for the response from resty client:

  1. error response. (it could be error timeout or some else)
  2. HTTP Status Code, which is the resp.StatusCode() (I would use this for this case)
  3. Response Body, which is the json.Unmarshal(resp.Body(), &yourStruct)

In your case I would suggest you try to validate the HTTP status code if the statusCode 404:

func PutItems( items []string) ([]string, string, rest_errors.RestErr){
  resp, err := client.R().
  SetHeader("Accept", "application/json").
  SetBody(myBody).
  Put(myEndpoint)
  
  if err != nil { // 404 don't happen here apparently
       retu…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BigBoulard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants