MCPcopy Create free account
hub / github.com/MarioCarrion/todo-api-microservice-example / ParseUpdateTaskResponse

Function ParseUpdateTaskResponse

client.gen.go:904–934  ·  view source on GitHub ↗

ParseUpdateTaskResponse parses an HTTP response from a UpdateTaskWithResponse call

(rsp *http.Response)

Source from the content-addressed store, hash-verified

902
903// ParseUpdateTaskResponse parses an HTTP response from a UpdateTaskWithResponse call
904func ParseUpdateTaskResponse(rsp *http.Response) (*UpdateTaskResponse, error) {
905 bodyBytes, err := io.ReadAll(rsp.Body)
906 defer func() { _ = rsp.Body.Close() }()
907 if err != nil {
908 return nil, err
909 }
910
911 response := &UpdateTaskResponse{
912 Body: bodyBytes,
913 HTTPResponse: rsp,
914 }
915
916 switch {
917 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400:
918 var dest ErrorResponse
919 if err := json.Unmarshal(bodyBytes, &dest); err != nil {
920 return nil, err
921 }
922 response.JSON400 = &dest
923
924 case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500:
925 var dest ErrorResponse
926 if err := json.Unmarshal(bodyBytes, &dest); err != nil {
927 return nil, err
928 }
929 response.JSON500 = &dest
930
931 }
932
933 return response, nil
934}

Callers 2

Calls 2

CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected