Skip to content
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

As a developers, API errors should be easier to get to and get the full details #3066

Closed
sebastienlevert opened this issue Aug 4, 2023 · 5 comments · Fixed by #3273
Closed
Assignees
Labels
generator Issues or improvements relater to generation capabilities. WIP
Milestone

Comments

@sebastienlevert
Copy link
Contributor

No description provided.

@sebastienlevert sebastienlevert converted this from a draft issue Aug 4, 2023
@sebastienlevert sebastienlevert self-assigned this Aug 4, 2023
@sebastienlevert
Copy link
Contributor Author

Related to microsoftgraph/msgraph-sdk-go#510

@sebastienlevert sebastienlevert added this to the Kiota v1.6 milestone Aug 4, 2023
@sebastienlevert sebastienlevert added the generator Issues or improvements relater to generation capabilities. label Aug 4, 2023
@baywet
Copy link
Member

baywet commented Aug 4, 2023

We already generate the error types based on the description. What's missing is mapping a field of that type to the "standard error message" for the error/exception in the runtime, so it's easier to get an actionable message.
For that we'd need an extension that tells us "this is the property you should get the message from".
We could either have that extension contain some jq/jamespath/jsonpath expression (but parsing it and handling complex cases might be a lot of work) or just scan all sub-properties in the error type for that "marker extension" (but then we need to define what happens if we find multiple entries).

@darrelmiller to help with the technical specification of that extension.

@darrelmiller
Copy link
Member

  1. If there is a x-ms-primaryErrorMessage: true annotation in the error schema, use that property as the message in the native exception object
  2. Otherwise, put the HTTP reason phrase in the exception message
  3. Add type of the exceptions that will be thrown in the request executor method comments
components:
  schemas:
    ODataError:
      type: object
      properties:
        code:   
          type: string
        message: 
          type: string
          x-ms-primaryErrorMessage: true

@Ducki
Copy link

Ducki commented Sep 26, 2023

Does the x-ms-primaryErrorMessage field also get recognized if it is on an inherited property further up the "chain"?

We have a ValidationProblem type, which inherits from HttpValidationProblem, which inherits from ProblemDetails. On the ProblemDetails object, we declare the detail property as the primary error message. Still, the exception message is Exception of type '[…]ValidationProblem' was thrown., the actual error is nowhere within the exception object.

@baywet
Copy link
Member

baywet commented Sep 26, 2023

The part that projects schemas to types should recognize the extension on the property and add the information to the property.
However the part that emits the path to that property only looks at the current type, not the inheritance chain.
This should be easy to adapt by recursively calling the method on the parent types.

internal static string GetPrimaryMessageCodePath<TBlockKind, TBlockDeclaration>(this ProprietableBlock<TBlockKind, TBlockDeclaration> block,

Don't hesitate to submit a pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants