Allow handling of NotFound
responses as an inner Err
in a nested Result
#1010
Labels
closed-for-staleness
feature-request
A feature should be added or improved.
p2
This is a standard priority issue
response-requested
Waiting on additional info and feedback. Will move to 'closing-soon' in 7 days.
Describe the feature
For some applications it is required to explicitly handle a
NotFound
response for some requests (such as an S3head_object
) as part of the application logic while other errors returned by the same API can be considered sufficiently unlikely to just abort with anexpect
/unwrap
or pass the error up to the caller with a?
. At the moment it requires quite a bit of boilerplate code to go through the nested error struct in order to distinguish aNotFound
response from other errors.From my point of view the best option would be to have a nested result with the outer
Result
indicating some form of hard error (network connectivity, permission issue, invalid server response etc.) and an innerResult
just containing the expected response or aNotFound
error. That way the application can directly handle theNotFound
error after getting rid of the outer error via a?
or anunwrap
/expect
. In order to not break existing applications this should probably be optional, see the section "Proposed solution" on how this could be implemented.Use Case
When using S3 it is sometimes required to check whether an object exists or not. At the moment it is pretty frustrating to go through the error response in order to find out whether it is an actual error or just a
NotFound
response which can be handled by the application logic.Proposed Solution
Changing the default behavior is likely not an option since this would break pretty much all existing applications. However it may be an option to add something like an
extract_not_found
method to extract theNotFound
error out of theSdkError
and move it to an innerResult
. Here is a prototype implementation I have written for the S3head_object
API:The
ExtractNotFound
implementation is pretty generic and could therefore directly be used for a large range of APIs. It will however require a type-specific implementation of theGetNotFound
trait for all the different auto-generated error types for the different API requests, so integrating this will likely require a change to the code generator.Other Information
No response
Acknowledgements
A note for the community
Community Note
The text was updated successfully, but these errors were encountered: