Browse Source

[fix]接收HttpApiHost报错信息,反馈到客户端

master
贾荣国 3 years ago
parent
commit
63895e6b5b
  1. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs
  2. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs
  3. 19
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs
  4. 15
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs
  5. 15
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs
  6. 15
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs
  7. 15
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs
  8. 16
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs

@ -2,7 +2,7 @@ using FluentValidation;
namespace Win_in.Sfs.Scp.WebApi;
public class CreatePurchaseOrderDetailValidator : AbstractValidator<PurchaseOrderDetailDTO>
public class CreatePurchaseOrderDetailValidator : AbstractValidator<PurchaseOrderDetailCreateDTO>
{
public CreatePurchaseOrderDetailValidator()
{

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs

@ -1,5 +1,6 @@
using Volo.Abp.Account;
using Volo.Abp.FeatureManagement;
using Volo.Abp.FluentValidation;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.ObjectExtending;
@ -17,7 +18,8 @@ namespace Win_in.Sfs.Scp.WebApi
typeof(AbpPermissionManagementApplicationContractsModule),
typeof(AbpSettingManagementApplicationContractsModule),
typeof(AbpTenantManagementApplicationContractsModule),
typeof(AbpObjectExtendingModule)
typeof(AbpObjectExtendingModule),
typeof(AbpFluentValidationModule)
)]
public class WebApiApplicationContractsModule : AbpModule
{

19
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs

@ -1,7 +1,11 @@
using System.Net.Mime;
using System;
using System.Net.Mime;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Volo.Abp;
namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
{
@ -27,10 +31,15 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
public virtual async Task<ActionResult<PartDTO>> CreateAsync([FromBody]PartCreateDto input)
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Part);
return Ok(dto);
try
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Part);
return Ok(dto);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}

15
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs

@ -1,4 +1,5 @@
using System.Net.Mime;
using System;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
[Produces(MediaTypeNames.Application.Xml)]
public virtual async Task<ActionResult<PurchaseOrderDTO>> CreateAsync([FromBody] PurchaseOrderCreateDTO input)
{
try
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.PurchaseOrder);
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.PurchaseOrder);
return Ok(dto);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
return Ok(dto);
}
}
}

15
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs

@ -1,4 +1,5 @@
using System.Net.Mime;
using System;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
[Produces(MediaTypeNames.Application.Xml)]
public virtual async Task<ActionResult<ReceiptDTO>> CreateAsync([FromBody] ReceiptCreateDTO input)
{
try
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Receipt);
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Receipt);
return Ok(dto);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
return Ok(dto);
}
}
}

15
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs

@ -1,4 +1,5 @@
using System.Net.Mime;
using System;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
[Produces(MediaTypeNames.Application.Xml)]
public virtual async Task<ActionResult<SupplierDTO>> CreateAsync([FromBody] SupplierCreateDTO input)
{
try
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Supplier);
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Supplier);
return Ok(dto);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
return Ok(dto);
}
}
}

15
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs

@ -1,4 +1,5 @@
using System.Net.Mime;
using System;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@ -23,10 +24,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
[Produces(MediaTypeNames.Application.Xml)]
public virtual async Task<ActionResult<UnplannedReceiptDTO>> CreateAsync([FromBody] UnplannedReceiptCreateDTO input)
{
try
{
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.UnplannedReceipt);
var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.UnplannedReceipt);
return Ok(dto);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
return Ok(dto);
}
}
}

16
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs

@ -7,6 +7,7 @@ using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Volo.Abp;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
@ -37,11 +38,16 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
var client = CreateClient();
var response = await client.PostAsJsonAsync(routeString, input);
response.EnsureSuccessStatusCode();
var str =await response.Content.ReadAsStringAsync();
var dto = await response.Content.ReadFromJsonAsync<TOutput>();
return dto;
if (response.IsSuccessStatusCode)
{
var dto = await response.Content.ReadFromJsonAsync<TOutput>();
return dto;
}
else
{
var str = await response.Content.ReadAsStringAsync();
throw new AbpException(str);
}
}
private HttpClient CreateClient()

Loading…
Cancel
Save