From f5fbbcd6a32c48a0428ab391f9c2e254426268ed Mon Sep 17 00:00:00 2001 From: Jeremia Noebel Date: Wed, 22 Nov 2023 13:36:27 +0100 Subject: [PATCH 1/3] add response headers and status code to returned error --- CHANGELOG.md | 6 ++++++ go.mod | 2 +- go.sum | 4 ++-- nethttp_request_adapter.go | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6e941..5e32faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +## [1.1.1] - 2023-11-22 + +### Added + +- Added response headers and status code to returned error in `throwIfFailedResponse`. + ## [1.1.0] - 2023-08-11 ### Added diff --git a/go.mod b/go.mod index c0d652a..1fbb268 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/google/uuid v1.4.0 - github.com/microsoft/kiota-abstractions-go v1.5.1 + github.com/microsoft/kiota-abstractions-go v1.5.2 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/otel v1.21.0 go.opentelemetry.io/otel/trace v1.21.0 diff --git a/go.sum b/go.sum index 6636cc0..a28d776 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/microsoft/kiota-abstractions-go v1.5.1 h1:MD/WiDEc68TMYyjAmyxKH4u6OU+gegMK82ht73dz98g= -github.com/microsoft/kiota-abstractions-go v1.5.1/go.mod h1:xyBzTVCYrp7QBW4/p+RFi44PHwp/IPn2dZepuV4nF80= +github.com/microsoft/kiota-abstractions-go v1.5.2 h1:rVGmtb0B557fCxVjHXUrSGXDWTdrIN/9gl6TTBan1fc= +github.com/microsoft/kiota-abstractions-go v1.5.2/go.mod h1:xyBzTVCYrp7QBW4/p+RFi44PHwp/IPn2dZepuV4nF80= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/std-uritemplate/std-uritemplate/go v0.0.47 h1:erzz/DR4sOzWr0ca2MgSTkMckpLEsDySaTZwVFQq9zw= diff --git a/nethttp_request_adapter.go b/nethttp_request_adapter.go index c9b25c3..8aaf3f2 100644 --- a/nethttp_request_adapter.go +++ b/nethttp_request_adapter.go @@ -808,7 +808,13 @@ func (a *NetHttpRequestAdapter) throwIfFailedResponse(ctx context.Context, respo } } + if apiErrorable, ok := errValue.(abs.ApiErrorable); ok { + apiErrorable.SetResponseHeaders(responseHeaders) + apiErrorable.SetStatusCode(response.StatusCode) + } + err = errValue.(error) + spanForAttributes.RecordError(err) return err } From 651bf8321b531ac6365162e56ff129fae116138e Mon Sep 17 00:00:00 2001 From: Jeremia Noebel Date: Wed, 22 Nov 2023 14:06:03 +0100 Subject: [PATCH 2/3] add response headers and status code to prematurely returned error --- nethttp_request_adapter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nethttp_request_adapter.go b/nethttp_request_adapter.go index 8aaf3f2..809a793 100644 --- a/nethttp_request_adapter.go +++ b/nethttp_request_adapter.go @@ -795,9 +795,9 @@ func (a *NetHttpRequestAdapter) throwIfFailedResponse(ctx context.Context, respo errValue, err := rootNode.GetObjectValue(errorCtor) if err != nil { spanForAttributes.RecordError(err) - if apiError, ok := err.(*abs.ApiError); ok { - apiError.ResponseStatusCode = response.StatusCode - apiError.ResponseHeaders = responseHeaders + if apiErrorable, ok := errValue.(abs.ApiErrorable); ok { + apiErrorable.SetResponseHeaders(responseHeaders) + apiErrorable.SetStatusCode(response.StatusCode) } return err } else if errValue == nil { From 92d11b664371f77f8d71922d0758dca2f4fb1b48 Mon Sep 17 00:00:00 2001 From: Jeremia Noebel Date: Wed, 22 Nov 2023 14:06:52 +0100 Subject: [PATCH 3/3] use correct err value --- nethttp_request_adapter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nethttp_request_adapter.go b/nethttp_request_adapter.go index 809a793..7896394 100644 --- a/nethttp_request_adapter.go +++ b/nethttp_request_adapter.go @@ -795,7 +795,7 @@ func (a *NetHttpRequestAdapter) throwIfFailedResponse(ctx context.Context, respo errValue, err := rootNode.GetObjectValue(errorCtor) if err != nil { spanForAttributes.RecordError(err) - if apiErrorable, ok := errValue.(abs.ApiErrorable); ok { + if apiErrorable, ok := err.(abs.ApiErrorable); ok { apiErrorable.SetResponseHeaders(responseHeaders) apiErrorable.SetStatusCode(response.StatusCode) }