func unmarshalError(req *Request) { bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body) if err != nil { req.Error = apierr.New("UnmarshaleError", req.HTTPResponse.Status, err) return } if len(bodyBytes) == 0 { req.Error = apierr.NewRequestError( apierr.New("UnmarshaleError", req.HTTPResponse.Status, fmt.Errorf("empty body")), req.HTTPResponse.StatusCode, "", ) return } var jsonErr jsonErrorResponse if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil { req.Error = apierr.New("UnmarshaleError", "JSON unmarshal", err) return } req.Error = apierr.NewRequestError( apierr.New(jsonErr.Code, jsonErr.Message, nil), req.HTTPResponse.StatusCode, "", ) }
// UnmarshalError unmarshals an error response for a JSON RPC service. func UnmarshalError(req *aws.Request) { defer req.HTTPResponse.Body.Close() bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body) if err != nil { req.Error = apierr.New("Unmarshal", "failed reading JSON RPC error response", err) return } if len(bodyBytes) == 0 { req.Error = apierr.NewRequestError( apierr.New("Unmarshal", req.HTTPResponse.Status, nil), req.HTTPResponse.StatusCode, "", ) return } var jsonErr jsonErrorResponse if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil { req.Error = apierr.New("Unmarshal", "failed decoding JSON RPC error response", err) return } codes := strings.SplitN(jsonErr.Code, "#", 2) req.Error = apierr.NewRequestError( apierr.New(codes[len(codes)-1], jsonErr.Message, nil), req.HTTPResponse.StatusCode, "", ) }