ParseUpdateTaskResponse parses an HTTP response from a UpdateTaskWithResponse call
(rsp *http.Response)
| 902 | |
| 903 | // ParseUpdateTaskResponse parses an HTTP response from a UpdateTaskWithResponse call |
| 904 | func 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 | } |
no test coverage detected