-
Notifications
You must be signed in to change notification settings - Fork 233
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
PHP - Add ResponseStatusCode to API error/exception #2243
Comments
@baywet we added the native response some time back -https://github.com/microsoft/kiota-abstractions-php/blob/dev/src/ApiException.php#L14 Thoughts? |
Thanks for sharing this. The only benefit I can see from doing this is the consumer has access to the response headers. But it muddies the water by requiring the consumer to know about the implementation type. |
Apologies, we should have discussed this more broadly. This came up as we were testing the first preview of the Kiota-generated SDK and we ran into issues with our requests during testing. We thought it would be helpful to add the native response to the exception to make it easy to debug failed requests. The native response type we opted to use is the PSR HTTP response type that is agreed & used across PHP HTTP clients, making it intuitive to handle for developers. |
I think adding more than the response code would be helpful for developers debugging failed requests |
no worries, it happens to make quick calls sometimes. |
No I don't foresee the need to access the response body but think it wouldn't hurt to provide the full response object for debugging. Perhaps for less standardized APIs than Graph, the schema may not perfectly align with the response? Idk |
I have two concerns with including the response body by default in the exception object. The first is from a performance perspective, we shouldn't make the default behaviour more expensive than it needs to be. I realize this is only for exception scenarios, but it isn't that uncommon for HTTP responses to also include HTML renderings of the error message. We don't want folks allocating memory to hold onto those payloads when they don't care about them. If they explicitly want to access the body then there should be a way to express that in code. |
Makes sense. Making the change. Does it make sense to expose response headers as well? |
Let's wait until we get demands for the headers at this point. It's not going to be a breaking change anyway so I'm comfortable doing it Post GA |
@darrelmiller @baywet how should we handle error responses in Graph core's Large File Upload, Page Iterator and Batch Requests considering the ODataError models are generated in the service lib? Should we define custom Realised we had added the full native response to the exception to provide response payload visibility during those errors. |
Why do the tasks need to deserialize errors instead of letting them bubble through and let the consumers, who will have the errors definitions, handle them? Can you give specific examples please? |
In a case like the Batch request builder, we'd need to specify error mappings for a failed request to make sense, otherwise the developer gets an |
This is where we might need a bit of plaster, and have the core one be a base type that needs the mappings in the constructor, and the derived one in the service lib set things up. What do you think? |
I don't understand how the core base type will initialise a derived type in the service lib. Or what the base type would look like. Would you mind sharing an example? |
classDiagram
BatchBase <|-- BatchV1
class BatchBase {
+constructor(map[string]factory errorMappings)
}
class BatchV1 {
+ constructor()
}
In the BatchV1 constructor, we just call the batch base constructor and pass a list of error mappings. The same kind of map that gets passed from the executor method to the request adapter send method. Does that clarify the suggestion? |
Makes sense. I wasn't clear whether we were refactoring the error types or the batch request builders. Will create another task to refactor our batch request builder. We initially provided it in the Core lib. |
related to #2216
To improve the error handling experience we need to add the status code the the main api error type:
Examples
microsoft/kiota-dotnet#68
microsoft/kiota-http-dotnet#82
The text was updated successfully, but these errors were encountered: