ParseCreateTaskResponse parses an HTTP response from a CreateTaskWithResponse call
(rsp *http.Response)
| 763 | |
| 764 | // ParseCreateTaskResponse parses an HTTP response from a CreateTaskWithResponse call |
| 765 | func ParseCreateTaskResponse(rsp *http.Response) (*CreateTaskResponse, error) { |
| 766 | bodyBytes, err := io.ReadAll(rsp.Body) |
| 767 | defer func() { _ = rsp.Body.Close() }() |
| 768 | if err != nil { |
| 769 | return nil, err |
| 770 | } |
| 771 | |
| 772 | response := &CreateTaskResponse{ |
| 773 | Body: bodyBytes, |
| 774 | HTTPResponse: rsp, |
| 775 | } |
| 776 | |
| 777 | switch { |
| 778 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: |
| 779 | var dest CreateTasksResponse |
| 780 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { |
| 781 | return nil, err |
| 782 | } |
| 783 | response.JSON201 = &dest |
| 784 | |
| 785 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: |
| 786 | var dest ErrorResponse |
| 787 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { |
| 788 | return nil, err |
| 789 | } |
| 790 | response.JSON400 = &dest |
| 791 | |
| 792 | case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: |
| 793 | var dest ErrorResponse |
| 794 | if err := json.Unmarshal(bodyBytes, &dest); err != nil { |
| 795 | return nil, err |
| 796 | } |
| 797 | response.JSON500 = &dest |
| 798 | |
| 799 | } |
| 800 | |
| 801 | return response, nil |
| 802 | } |
| 803 | |
| 804 | // ParseSearchTaskResponse parses an HTTP response from a SearchTaskWithResponse call |
| 805 | func ParseSearchTaskResponse(rsp *http.Response) (*SearchTaskResponse, error) { |
no test coverage detected