You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So that if the call to GetPetById() fails then we can handle the negative response ourselves instead of catching an ApiException
varclient=RestService.For<ISwaggerPetstore>("https://petstore3.swagger.io/api/v3");varresponse=awaitclient.GetPetById(2);if(!response.IsSuccessStatusCode){// Do something about the failed response}varpet=response.Content;
The IApiResponse<T> interface comes from Refit and is defined as
/// <inheritdoc/>publicinterfaceIApiResponse<outT>:IApiResponse{/// <summary>/// Deserialized request content as <typeparamref name="T"/>./// </summary>T?Content{get;}}/// <summary>/// Base interface used to represent an API response./// </summary>publicinterfaceIApiResponse:IDisposable{/// <summary>/// HTTP response headers./// </summary>HttpResponseHeadersHeaders{get;}/// <summary>/// HTTP response content headers as defined in RFC 2616./// </summary>HttpContentHeaders?ContentHeaders{get;}/// <summary>/// Indicates whether the request was successful./// </summary>boolIsSuccessStatusCode{get;}/// <summary>/// HTTP response status code./// </summary>HttpStatusCodeStatusCode{get;}/// <summary>/// The reason phrase which typically is sent by the server together with the status code./// </summary>string?ReasonPhrase{get;}/// <summary>/// The HTTP Request message which led to this response./// </summary>HttpRequestMessage?RequestMessage{get;}/// <summary>/// HTTP Message version./// </summary>VersionVersion{get;}/// <summary>/// The <see cref="ApiException"/> object in case of unsuccessful response./// </summary>ApiException?Error{get;}}
The text was updated successfully, but these errors were encountered:
Add support for generating interfaces that returns
Task<IApiResponse<T>>
as the return typeLike this:
So that if the call to
GetPetById()
fails then we can handle the negative response ourselves instead of catching anApiException
The
IApiResponse<T>
interface comes from Refit and is defined asThe text was updated successfully, but these errors were encountered: