Skip to content

Commit

Permalink
Merge pull request #125 from NerdJeremia/fix/response-headers-in-retu…
Browse files Browse the repository at this point in the history
…rned-error

add response headers and status code to returned error
  • Loading branch information
baywet authored Nov 22, 2023
2 parents 7176e1c + 92d11b6 commit 390840a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
12 changes: 9 additions & 3 deletions nethttp_request_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := err.(abs.ApiErrorable); ok {
apiErrorable.SetResponseHeaders(responseHeaders)
apiErrorable.SetStatusCode(response.StatusCode)
}
return err
} else if errValue == nil {
Expand All @@ -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
}

0 comments on commit 390840a

Please sign in to comment.