refactor: 统一业务异常处理,标准化结果码和错误响应
1. 新增并完善ResultCode枚举,补充标准HTTP状态码对应的业务状态码 2. 重构BusinessException,新增基于ResultCode的构造函数和ThrowIf扩展方法 3. 替换所有硬编码的HTTP状态码为统一的ResultCode枚举 4. 优化全局异常中间件,根据业务状态码映射对应HTTP状态码并规范化JSON响应 5. 修复OssImageHelper和AutoDotCodeConsumer中的OSS文件处理逻辑 6. 新增用户答题快照实体类 7. 清理废弃的宠物模块迁移脚本
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QYZH.InteractiveMagazine.Common.Extensions;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||
|
||||
@ -87,7 +88,7 @@ public class OssImageHelper
|
||||
catch (Exception ex) when (ex is not BusinessException)
|
||||
{
|
||||
_logger.LogError(ex, "OSS 图片搬运异常,Source: {Source}, Target: {Target}", sourcePath, targetPath);
|
||||
throw new BusinessException("图片搬运失败,请重试", 500);
|
||||
throw new BusinessException("图片搬运失败,请重试", ResultCode.GLOBAL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ using CSRedis;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using QYZH.InteractiveMagazine.Common.Extensions;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using System.Text.Json;
|
||||
using System.Web;
|
||||
|
||||
@ -193,6 +195,53 @@ namespace QYZH.InteractiveMagazine.Infrastructure.OSS
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断对象是否存在
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public bool DoesObjectExist(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key.IsNull()) return false;
|
||||
|
||||
key = key.RemoveDomain();
|
||||
key = HttpUtility.UrlDecode(key);
|
||||
|
||||
return _ossClient.DoesObjectExist(_ossOption.BucketName, key);
|
||||
}
|
||||
catch (OssException ex)
|
||||
{
|
||||
_logger.LogError(ex.Message + ex.StackTrace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取对象内容流
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public Stream? GetObjectStream(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (key.IsNull()) return null;
|
||||
|
||||
key = key.RemoveDomain();
|
||||
key = HttpUtility.UrlDecode(key);
|
||||
|
||||
var ossObject = _ossClient.GetObject(_ossOption.BucketName, key);
|
||||
return ossObject.Content;
|
||||
}
|
||||
catch (OssException ex)
|
||||
{
|
||||
_logger.LogError(ex.Message + ex.StackTrace);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除多个
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user