func parseArmErrorFromResponse()

in pkg/middleware/arm_error_collector.go [156:170]


func parseArmErrorFromResponse(resp *http.Response) *ArmError {
	if resp == nil {
		return &ArmError{Code: ArmErrorCodeUnexpectedTransportError, Message: "nil response"}
	}
	if resp.StatusCode > 399 {
		// for 4xx, 5xx response, ARM should include {error:{code, message}} in the body
		err := runtime.NewResponseError(resp)
		respErr := &azcore.ResponseError{}
		if errors.As(err, &respErr) {
			return &ArmError{Code: ArmErrorCode(respErr.ErrorCode), Message: respErr.Error()}
		}
		return &ArmError{Code: ArmErrorCodeCastToArmResponseErrorFailed, Message: fmt.Sprintf("Response body is not in ARM error form: {error:{code, message}}: %s", err.Error())}
	}
	return nil
}