From 79f931c51b47bf1f8f721a44708550842c711ef9 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Wed, 26 Feb 2020 21:14:07 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=BC=BA=20OneDrive=20?= =?UTF-8?q?=E8=B0=83=E7=94=A8,=20=E5=A6=82=E8=B0=83=E7=94=A8=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5,=20=E5=B0=9D=E8=AF=95=E9=87=8D=E6=96=B0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20token=20=E5=90=8E,=20=E5=86=8D=E6=AC=A1=E8=AF=B7?= =?UTF-8?q?=E6=B1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/AbstractOneDriveService.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/im/zhaojun/onedrive/common/service/AbstractOneDriveService.java b/src/main/java/im/zhaojun/onedrive/common/service/AbstractOneDriveService.java index bd9e27f..90b015b 100644 --- a/src/main/java/im/zhaojun/onedrive/common/service/AbstractOneDriveService.java +++ b/src/main/java/im/zhaojun/onedrive/common/service/AbstractOneDriveService.java @@ -16,7 +16,9 @@ import im.zhaojun.common.service.AbstractFileService; import im.zhaojun.common.service.StorageConfigService; import im.zhaojun.common.util.StringUtils; import im.zhaojun.onedrive.common.model.OneDriveToken; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; @@ -28,6 +30,7 @@ import java.util.List; * @author Zhao Jun * 2020/1/29 11:54 */ +@Slf4j public abstract class AbstractOneDriveService extends AbstractFileService { protected static final String DRIVER_INFO_URL = "https://{graphEndPoint}/v1.0/me/drives"; @@ -109,7 +112,15 @@ public abstract class AbstractOneDriveService extends AbstractFileService { } fullPath = StringUtils.removeLastSeparator(fullPath); - ResponseEntity responseEntity = oneDriveRestTemplate.getForEntity(requestUrl, String.class, getGraphEndPoint(), fullPath); + ResponseEntity responseEntity; + try { + responseEntity = oneDriveRestTemplate.getForEntity(requestUrl, String.class, getGraphEndPoint(), fullPath); + } catch (HttpClientErrorException e) { + log.debug("调用 OneDrive 时出现了网络异常: {} , 已尝试重新刷新 token 后再试.", e.getMessage()); + refreshOneDriveToken(); + responseEntity = oneDriveRestTemplate.getForEntity(requestUrl, String.class, getGraphEndPoint(), fullPath); + } + String body = responseEntity.getBody(); JSONObject root = JSON.parseObject(body);