Skip to content

ODataError generates generic (i.e."empty") .Error() in some cases #313

Closed

Description

@XANi

TL;DR version ODataError{} is embedding ApiError but does not set message which means .Error() returns default message in some cases

I was trying to get some demo code running and this

	result, err := client.Me().Get(context.Background(), nil)

returned error status code received from the API and type being *odataerrors.ODataError which embeds ApiError type, yet doesn't set it in some cases (ApiError generates generic message like above when Message is zero length.

// ODataError 
type ODataError struct {
    i2ae4187f7daee263371cb1c977df639813ab50ffa529013b7437480d1ec0158f.ApiError
    // Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
    additionalData map[string]interface{}
    // The error property
    error MainErrorable
}

In the end to extract actual error message I needed to do

		switch v := err.(type) {
		case *odataerrors.ODataError:
			errorable := v.GetError()

			fmt.Printf("error: %s | %s\n",
				*errorable.GetCode(),
				*errorable.GetMessage(),
			)
			details := errorable.GetDetails()
			for idx, v := range details {
				fmt.Printf("  %d - %s %s\n",
					idx,
					*v.GetMessage(),
					*v.GetCode(),
				)
			}
			extras := v.GetAdditionalData()
			for k, v := range extras {
				fmt.Printf("k: %s: %T %+v\n", k, v, v)
			}

		default:
			fmt.Printf("err: %s", err)
		}

which is not exactly easy and frankly I'm not sure why it even embeds ApiError instead of just having its own .Error() method

Activity

  1. rkodev commented on Nov 17, 2022

    @rkodev
    Contributor

    Hi XANi (@XANi) Thanks for trying out the SDK, we are currently reviewing this error format in order to improve on this.

    1. We are evaluating whether or not to have the ApiError embedded in the error response as this does seem to not to always have the error
    2. Ensuring the method .Error() returns the error that was experienced
  2. baywet commented on Jan 24, 2023

    @baywet
    Member

    Consolidating multiple issues here for clarity with #334 and #370.

    Part of the issue lies in the serialization and metadata being inaccurate as Ronald K (@rkodev) mentioned "this is the case for the given issue, the returned error from the api is innererror as opposed to innerError"

    Part of the enhancement request is that assuming the serialization issue is fixed, the standard Error() behavior is not supported due to the way the code is generated today and we should probably review this.

  3. rkodev commented on Apr 12, 2023

    @rkodev
    Contributor

    Hi XANi (@XANi) , This issue is resolved as tested in version 0.61.0 of the sdk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions