-
Notifications
You must be signed in to change notification settings - Fork 166
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
[LLC] Set "default response classifier" on message #1535
Comments
@AlexanderSher, can you confirm this is the design we want to go with before we assign it? |
There is one limitation with this approach: users won't be able to customize how exceptions are created. I'd prefer classifier to be internal (rather than private) with method |
Hi Alexander, the user will still be able to customize exception creation because we plan to move the customization to ResponseClassifier in Azure/azure-sdk-for-net#24031
if (response.IsError())
{
throw new RequestFailedException(response);
} I am working on this as part of Azure/azure-sdk-for-net#23372 |
Ok, let's say a user needs custom error code handling and custom exception types. How this will be customized? |
Custom error code handling was previously exposed via the Customizing exceptions currently happens in the internal shared source class |
Regarding the API we selected instead of |
To close the loop here - @AlexanderSher and I chatted, and we'll move forward with this approach. There is a feature request from another team for error customization and @AlexanderSher is going to file an issue to track that -- once we have that we can decide on a timeline for addressing it and whether or not it should be part of LLC RC1. |
@annelo-msft @pakrym await Pipeline.SendAsync(message, options?.CancellationToken ?? default).ConfigureAwait(false);
var statusOption = options?.StatusOption ?? ResponseStatusOption.Default;
if (statusOption == ResponseStatusOption.NoThrow)
{
return message.Response;
}
else
{
if (!message.ResponseClassifier.IsErrorResponse(message))
{
return message.Response;
}
else
{
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
}
} |
@AlexanderSher that's a great observation! Wonder if we can move this code into some shared file and not codegen it. |
This is the code we generate right now for the switch (message.Response.Status)
{
case int s when s >= 200 && s < 300:
return Response.FromValue(true, message.Response);
case int s when s >= 400 && s < 500:
return Response.FromValue(false, message.Response);
default:
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
} Which part of it should go into |
Great question, @AlexanderSher! In this case, we wouldn't use the standard code you noted in #1535 (comment). Instead, since we need to return if (!message.ResponseClassifier.IsErrorResponse(message))
{
return Response.FromValue(message.Response.Status >= 200 && message.Response.Status < 300, message.Response);
}
if (options.StatusOption == ResponseStatusOption.NoThrow)
{
return new ErrorResponse<bool>(message.Response, _clientDiagnostics.CreateRequestFailedException(message.Response));
}
else
{
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
} With the ResponseClassifier being: private class ResponseClassifier200204404 : ResponseClassifier
{
public override bool IsErrorResponse(HttpMessage message)
{
switch (message.Response.Status)
{
case 200:
case 204:
case 404:
return false;
default:
return true;
}
}
} What are your thoughts on this proposal? |
|
I agree it's a special case, and I think it's interesting -- thanks for calling this out @AlexanderSher. Given this, I'd suggest we continue generating classifiers in the same way as other methods so we handle if (!message.ResponseClassifier.IsErrorResponse(message))
{
bool resourceExists = message.Response.Status == 200 || message.Response.Status ==204;
return Response.FromValue(resourceExists, message.Response);
} I'm not tied to this specific implementation, though, so happy to discuss alternatives... |
- Fix Azure#1535: [LLC] Set "default response classifier" on message - Incapsulate common code into shared code to reduce amount of generated code
* - Join back LLC Client and RestClient types - Fix #1535: [LLC] Set "default response classifier" on message - Incapsulate common code into shared code to reduce amount of generated code * Rename *RestClient into *Client * Revert test changes
In order for us to allow
Response.IsError
to reflect default behavior (i.e. which status codes are defined in the OpenAPI spec as success vs. error), we need to pass this information to the pipeline so it can be set on the response.We achieve this via setting the
ResponseClassifier
on the message when the request is created.In the LLC generator, we will need to:
In addition, we will:
4. Remove the
RequestOptions
allocation from the default pathThe text was updated successfully, but these errors were encountered: