From 887919552da0529e8e32e028610025fb9191c19c Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 16 Aug 2016 12:27:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=AF=A6=E7=BB=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/Yum/managers/DownloadManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/pw/yumc/Yum/managers/DownloadManager.java b/src/main/java/pw/yumc/Yum/managers/DownloadManager.java index 6d0bf11..e26f838 100644 --- a/src/main/java/pw/yumc/Yum/managers/DownloadManager.java +++ b/src/main/java/pw/yumc/Yum/managers/DownloadManager.java @@ -149,6 +149,17 @@ public class DownloadManager { sender.sendMessage("§6开始下载: §3" + getFileName(url)); sender.sendMessage("§6下载地址: §3" + url.toString()); final URLConnection uc = reload(sender, url.openConnection()); + final int status = ((HttpURLConnection) uc).getResponseCode(); + if (status != HttpURLConnection.HTTP_OK) { + switch (status) { + case HttpURLConnection.HTTP_NOT_FOUND: + throw new IllegalStateException(status + " 文件未找到!"); + case HttpURLConnection.HTTP_FORBIDDEN: + throw new IllegalStateException(status + " 服务器拒绝了访问!"); + case HttpURLConnection.HTTP_BAD_GATEWAY: + throw new IllegalStateException(status + " 无效的网关!"); + } + } final int fileLength = uc.getContentLength(); if (fileLength < 0) { sender.sendMessage("§6下载: §c文件 " + file.getName() + " 获取长度错误(可能是网络问题)!");