Sha256: c749b4080baee0185a608729670d24f0fea88a5ad2d3075f850798e683b3d0ea

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

package xml

import (
	"encoding/xml"
	"fmt"
	"io"
)

// ErrorComponents represents the error response fields
// that will be deserialized from an xml error response body
type ErrorComponents struct {
	Code    string
	Message string
}

// GetErrorResponseComponents returns the error fields from an xml error response body
func GetErrorResponseComponents(r io.Reader, noErrorWrapping bool) (ErrorComponents, error) {
	if noErrorWrapping {
		var errResponse noWrappedErrorResponse
		if err := xml.NewDecoder(r).Decode(&errResponse); err != nil && err != io.EOF {
			return ErrorComponents{}, fmt.Errorf("error while deserializing xml error response: %w", err)
		}
		return ErrorComponents{
			Code:    errResponse.Code,
			Message: errResponse.Message,
		}, nil
	}

	var errResponse wrappedErrorResponse
	if err := xml.NewDecoder(r).Decode(&errResponse); err != nil && err != io.EOF {
		return ErrorComponents{}, fmt.Errorf("error while deserializing xml error response: %w", err)
	}
	return ErrorComponents{
		Code:    errResponse.Code,
		Message: errResponse.Message,
	}, nil
}

// noWrappedErrorResponse represents the error response body with
// no internal <Error></Error wrapping
type noWrappedErrorResponse struct {
	Code    string `xml:"Code"`
	Message string `xml:"Message"`
}

// wrappedErrorResponse represents the error response body
// wrapped within <Error>...</Error>
type wrappedErrorResponse struct {
	Code    string `xml:"Error>Code"`
	Message string `xml:"Error>Message"`
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/aws/smithy-go/encoding/xml/error_utils.go