public class DmsAfterSalesClientService : DomainService { private readonly IDmsAfterSalesApi _api; private readonly ILogger<DcsPartClientService> _logger; private const string From = "Dms After Sales"; public DmsAfterSalesClientService(IDmsAfterSalesApi api, ILogger<DcsPartClientService> logger) { _api = api; _logger = logger; } private async Task<Exception> WrapException(ApiException exception) { if (exception.StatusCode == System.Net.HttpStatusCode.BadRequest) { var receivedBody = await exception.GetContentAsAsync<ResponseBody>(); return new ValidationException($"业务校验失败,{receivedBody.Message} ({From})", exception); } else { _logger.LogWarning(exception, "Call Dms After Sales API failed"); return new ApplicationException($"内部挪用失败,{exception.Message} ({exception.StatusCode}) ({From})", exception); } } private Exception WrapException(HttpRequestException exception) { _logger.LogWarning(exception, "Call Dms After Sales API failed"); return new ApplicationException($"内部挪用失败,{exception.Message} ({From})", exception); } public async Task UpdateCustomerAmount([Body] PartRetailSettlementModel input) { try { await _api.UpdateCustomerAmount(input); } catch (ApiException ex) { throw await WrapException(ex); } catch (HttpRequestException ex) { throw WrapException(ex); } } public async Task<decimal> RepairShortagePartCheckCustomerAccount([Body] RepairShortagePartModel input) { try { var result = await _api.RepairShortagePartCheckCustomerAccount(input); return result.Payload.BalanceAmount; } catch (ApiException ex) { throw await WrapException(ex); } catch (HttpRequestException ex) { throw WrapException(ex); } } public async Task<GetMemberCodeBrandCodeForVehicleOutput> GetMemberCodeBrandCodeForVehicle([Body]Guid vehicleId) { try { var result = await _api.GetMemberCodeBrandCodeForVehicle(vehicleId); return result.Payload; } catch (ApiException ex) { throw await WrapException(ex); } catch (HttpRequestException ex) { throw WrapException(ex); } } }
如安在Asp.Net Core中集成Refit(5)
内容版权声明:除非注明,否则皆为本站原创文章。