From d43190d74c869fb941de112b276968736976d4a0 Mon Sep 17 00:00:00 2001 From: shiker <32234876+shiker1996@users.noreply.github.com> Date: Sun, 23 Oct 2022 22:18:10 +0800 Subject: [PATCH] Fix the problem of deleting attachment on USS but failed (#2607) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core /milestone 1.6.x #### What this PR does / why we need it: 修复又拍云附件删除成功,但是管理页面的“internal server error” 报警 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2603 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note 修复又拍云附件删除成功仍旧提示错误的问题 ``` --- .../run/halo/app/handler/file/UpOssFileHandler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/run/halo/app/handler/file/UpOssFileHandler.java b/src/main/java/run/halo/app/handler/file/UpOssFileHandler.java index f07453de6..5a581ed46 100644 --- a/src/main/java/run/halo/app/handler/file/UpOssFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/UpOssFileHandler.java @@ -138,11 +138,12 @@ public class UpOssFileHandler implements FileHandler { try { Response result = manager.deleteFile(key, null); - HashMap respondBody = JsonUtils.jsonToObject(result.body().string(), HashMap.class); - if (!result.isSuccessful() - && !(result.code() == 404 && respondBody.get("code").equals(40400001))) { - log.warn("附件 " + key + " 从又拍云删除失败"); - throw new FileOperationException("附件 " + key + " 从又拍云删除失败"); + if (result.code() != 200) { + HashMap respondBody = JsonUtils.jsonToObject(result.body().string(), HashMap.class); + if (!(result.code() == 404 && respondBody.get("code").equals(40400001))) { + log.warn("附件 " + key + " 从又拍云删除失败"); + throw new FileOperationException("附件 " + key + " 从又拍云删除失败"); + } } } catch (IOException | UpException e) { e.printStackTrace();