Просмотр исходного кода

fix: 代理失败时展示友好错误页而非重定向长 URL

URL 长度 7274 字符,服务端代理请求第三方也返回 400。
fallback 的 sendRedirect 会把浏览器再次导向长 URL,改为展示友好错误页。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 22 часов назад
Родитель
Сommit
6ff7d06368

+ 9 - 1
car-wash-miniapp/src/main/java/com/kym/miniapp/controller/ParkingCouponController.java

@@ -83,7 +83,15 @@ public class ParkingCouponController {
             response.getWriter().write(content);
         } catch (Exception e) {
             log.error("代理停车券页面失败, url: {}", url, e);
-            response.sendRedirect(url);
+            response.setContentType("text/html; charset=utf-8");
+            response.getWriter().write("""
+                <!DOCTYPE html>
+                <html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
+                <title>服务暂不可用</title>
+                <style>body{font-family:sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#f5f5f5}
+                .card{background:#fff;padding:32px 24px;border-radius:8px;text-align:center;box-shadow:0 2px 12px rgba(0,0,0,.08)}
+                h2{color:#e67e22;margin:0 0 8px}p{color:#666;margin:0}</style>
+                </head><body><div class="card"><h2>服务暂不可用</h2><p>停车优惠页面暂时无法访问,请稍后重试或联系客服</p></div></body></html>""");
         }
     }