-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response headers are not added to returned error #110
Comments
Hi @NerdJeremia |
Hey @baywet, first of all thanks for your fast response. As you can see the headers are not set in the |
Thanks for the additional information. |
Sure. This is the definition of the error
In my understanding the ResponseHeaders should be in the field |
Thanks for sharing the additional information.
|
Thanks for your reply. I will try it. |
Hey @baywet, Sorry for the late reply but these are the things I found: In the The package models
import (
i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f "github.com/microsoft/kiota-abstractions-go"
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91 "github.com/microsoft/kiota-abstractions-go/serialization"
)
type CmpErrorResponse struct {
i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.ApiError
code *CmpErrorCode
description *string
details *string
stacktrace *string
typeEscaped *CmpErrorType
}
func NewCmpErrorResponse()(*CmpErrorResponse) {
m := &CmpErrorResponse{
ApiError: *i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.NewApiError(),
}
return m
}
func CreateCmpErrorResponseFromDiscriminatorValue(parseNode i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable, error) {
return NewCmpErrorResponse(), nil
}
func (m *CmpErrorResponse) Error()(string) {
return m.ApiError.Error()
}
func (m *CmpErrorResponse) GetCode()(*CmpErrorCode) {
return m.code
}
func (m *CmpErrorResponse) GetDescription()(*string) {
return m.description
}
func (m *CmpErrorResponse) GetDetails()(*string) {
return m.details
}
func (m *CmpErrorResponse) GetFieldDeserializers()(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error)) {
res := make(map[string]func(i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode)(error))
res["code"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetEnumValue(ParseCmpErrorCode)
if err != nil {
return err
}
if val != nil {
m.SetCode(val.(*CmpErrorCode))
}
return nil
}
res["description"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetDescription(val)
}
return nil
}
res["details"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetDetails(val)
}
return nil
}
res["stacktrace"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetStringValue()
if err != nil {
return err
}
if val != nil {
m.SetStacktrace(val)
}
return nil
}
res["type"] = func (n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error {
val, err := n.GetEnumValue(ParseCmpErrorType)
if err != nil {
return err
}
if val != nil {
m.SetTypeEscaped(val.(*CmpErrorType))
}
return nil
}
return res
}
func (m *CmpErrorResponse) GetStacktrace()(*string) {
return m.stacktrace
}
func (m *CmpErrorResponse) GetTypeEscaped()(*CmpErrorType) {
return m.typeEscaped
}
func (m *CmpErrorResponse) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.SerializationWriter)(error) {
if m.GetCode() != nil {
cast := (*m.GetCode()).String()
err := writer.WriteStringValue("code", &cast)
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("description", m.GetDescription())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("details", m.GetDetails())
if err != nil {
return err
}
}
{
err := writer.WriteStringValue("stacktrace", m.GetStacktrace())
if err != nil {
return err
}
}
if m.GetTypeEscaped() != nil {
cast := (*m.GetTypeEscaped()).String()
err := writer.WriteStringValue("type", &cast)
if err != nil {
return err
}
}
return nil
}
func (m *CmpErrorResponse) SetCode(value *CmpErrorCode)() {
m.code = value
}
func (m *CmpErrorResponse) SetDescription(value *string)() {
m.description = value
}
func (m *CmpErrorResponse) SetDetails(value *string)() {
m.details = value
}
func (m *CmpErrorResponse) SetStacktrace(value *string)() {
m.stacktrace = value
}
func (m *CmpErrorResponse) SetTypeEscaped(value *CmpErrorType)() {
m.typeEscaped = value
}
// CmpErrorResponseable
type CmpErrorResponseable interface {
i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.Parsable
GetCode()(*CmpErrorCode)
GetDescription()(*string)
GetDetails()(*string)
GetStacktrace()(*string)
GetTypeEscaped()(*CmpErrorType)
SetCode(value *CmpErrorCode)()
SetDescription(value *string)()
SetDetails(value *string)()
SetStacktrace(value *string)()
SetTypeEscaped(value *CmpErrorType)()
} These then never get set to hold the values of the actual response headers in the err = errValue.(error)
spanForAttributes.RecordError(err)
errRef := setApiErrorResponse(err, response, responseHeaders)
if errRef != nil {
// Handle the error
return err
}
return err func setApiErrorResponse(errValue error, response *nethttp.Response, responseHeaders *abs.ResponseHeaders) error {
val := reflect.ValueOf(errValue).Elem() // Elem returns the value that the pointer 'errValue' points to
// Check if the struct has the field 'ApiError'
apiErrorField := val.FieldByName("ApiError")
if !apiErrorField.IsValid() {
return &abs.ApiError{
Message: "ApiError field could not be set",
ResponseStatusCode: response.StatusCode,
ResponseHeaders: responseHeaders,
}
}
// Construct the ApiError we want to set
apiError := abs.ApiError{
ResponseStatusCode: response.StatusCode,
ResponseHeaders: responseHeaders,
}
// Set the field - this requires that the field is settable (exported)
if apiErrorField.CanSet() {
apiErrorField.Set(reflect.ValueOf(apiError))
} else {
return &abs.ApiError{
Message: "ApiError field could not be set",
ResponseStatusCode: response.StatusCode,
ResponseHeaders: responseHeaders,
}
}
return nil
} I don’t think it is ideal but I was able to set the proper response headers that way. |
Thanks for the additional information @NerdJeremia kiota-http-go/nethttp_request_adapter.go Line 811 in 243b44c
I don't think there's a need for reflection, a type assertion should be enough like we're doing above. Would you be willing to submit a pull request to correct the issue? |
Thanks for the reply. I think we can either use reflection or pass the response headers through all the functions to where the new |
Something you might not have noticed is that all custom errors inherit from ApiError. So type assertions should work (pointer to pointer) |
Right, because it's actually one of the member types that's an API error.
Thoughts? |
Sounds like a plan I will take a look |
Hi @baywet, I tested it locally and it worked! Thanks for the suggestion. |
Related to: #81
I noticed that the request headers are only being added to the returned error if the function returns prematurely.
Would be nice if someone could take a look at it.
kiota-http-go/nethttp_request_adapter.go
Lines 811 to 813 in b162cb6
The text was updated successfully, but these errors were encountered: