| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using System.Threading.Tasks; |
| | | using gdbg.Models; |
| | | using gdbg.Services; |
| | | using System.Collections.Generic; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Oracle.ManagedDataAccess.Client; |
| | | using gdbg.Models; |
| | | using System.Collections.Generic; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace gdbg.Controllers |
| | | { |
| | |
| | | // 其他 Oracle 错误 |
| | | return StatusCode(500, new |
| | | { |
| | | message = "数据库错误:" + ex.Message |
| | | // message = "数据库错误:" + ex.Message |
| | | message = ExtractErrorMessage(ex.Message) |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | // 如果无法匹配,则返回完整错误信息 |
| | | return oracleMessage; |
| | | }*/ |
| | | private static string ExtractErrorMessage(string oracleMessage) |
| | | /* private static string ExtractErrorMessage(string oracleMessage) |
| | | { |
| | | // 匹配多个 ORA-20002: 后的段落,提取最后一个 |
| | | var matches = System.Text.RegularExpressions.Regex.Matches( |
| | |
| | | |
| | | // 默认返回原始错误 |
| | | return oracleMessage; |
| | | }*/ |
| | | |
| | | |
| | | private static string ExtractErrorMessage(string oracleMessage) |
| | | { |
| | | // 匹配所有 ORA-20002: 错误段 |
| | | var matches = Regex.Matches(oracleMessage, @"ORA-20002:\s*(.*?)(?=(ORA-\d{5}:|$))", RegexOptions.Singleline); |
| | | |
| | | if (matches.Count > 0) |
| | | { |
| | | // 返回最里面一条(最后一个) |
| | | string raw = matches[matches.Count - 1].Groups[1].Value; |
| | | |
| | | // 去掉类似 "Error in PrintAndUpdate procedure:" 开头 |
| | | string cleaned = Regex.Replace(raw, @"^Error.*?:", "", RegexOptions.IgnoreCase).Trim(); |
| | | |
| | | return string.IsNullOrWhiteSpace(cleaned) ? raw.Trim() : cleaned; |
| | | } |
| | | |
| | | return oracleMessage; // fallback |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |