use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class ReactiveGlobalExceptionHandler method exceptionHandler.
@ExceptionHandler(Exception.class)
@ResponseBody
public WrapperResponse<?> exceptionHandler(ServerHttpRequest request, ServerHttpResponse response, Exception e) {
WrapperResponse<?> resp = new WrapperResponse<>();
e = (Exception) getActualThrowable(e);
if (e instanceof JeesuiteBaseException) {
JeesuiteBaseException e1 = (JeesuiteBaseException) e;
resp.setCode(e1.getCode());
resp.setMsg(e1.getMessage());
} else if (e instanceof MethodArgumentNotValidException) {
resp.setCode(400);
List<ObjectError> errors = ((MethodArgumentNotValidException) e).getBindingResult().getAllErrors();
String fieldName;
StringBuilder fieldNames = new StringBuilder();
for (ObjectError error : errors) {
fieldName = parseFieldName(error);
fieldNames.append(fieldName).append(",");
}
resp.setBizCode("error.parameter.notValid");
resp.setMsg("参数错误[" + fieldNames.toString() + "]");
} else {
Throwable parent = e.getCause();
if (parent instanceof IllegalStateException) {
resp.setCode(501);
resp.setMsg(e.getMessage());
} else {
resp.setCode(500);
resp.setMsg("系统繁忙");
}
}
//
ActionLogCollector.onResponseEnd(response.getRawStatusCode(), e);
return resp;
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method getObjectInputStream.
@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
bucketName = buildBucketName(bucketName);
String downloadUrl = getDownloadUrl(bucketName, fileKey, 600);
Request request = new Request.Builder().url(downloadUrl).build();
okhttp3.Response re = null;
try {
re = httpClient.newCall(request).execute();
if (re.isSuccessful()) {
return re.body().byteStream();
}
throw new JeesuiteBaseException(re.code(), re.message());
} catch (IOException e) {
throw new JeesuiteBaseException(e.getMessage());
}
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method getObjectBytes.
@Override
public byte[] getObjectBytes(String bucketName, String fileKey) {
bucketName = buildBucketName(bucketName);
String downloadUrl = getDownloadUrl(bucketName, fileKey, 600);
Request request = new Request.Builder().url(downloadUrl).build();
okhttp3.Response re = null;
try {
re = httpClient.newCall(request).execute();
if (re.isSuccessful()) {
return re.body().bytes();
}
throw new JeesuiteBaseException(re.code(), re.message());
} catch (IOException e) {
throw new JeesuiteBaseException(e.getMessage());
}
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method buildBucketUrlPrefix.
protected String buildBucketUrlPrefix(String buketName) {
String rs = "";
String path = "/v6/domain/list?tbl=" + buketName + "\n";
String accessToken = auth.sign(path);
String url = "http://api.qiniu.com/v6/domain/list?tbl=" + buketName;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).addHeader("Host", "api.qiniu.com").addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Authorization", "QBox " + accessToken).build();
okhttp3.Response re = null;
try {
re = client.newCall(request).execute();
if (re.isSuccessful() == true) {
String[] reArr = JsonUtils.toObject(re.body().string(), String[].class);
if (reArr.length > 0) {
rs = reArr[0];
if (!rs.endsWith(FilePathHelper.DIR_SPLITER)) {
rs = rs.concat(FilePathHelper.DIR_SPLITER);
}
}
} else {
throw new JeesuiteBaseException(re.message());
}
} catch (IOException e) {
throw new JeesuiteBaseException(e.getMessage());
}
return rs;
}
use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.
the class QiniuProvider method exists.
@Override
public boolean exists(String bucketName, String fileKey) {
bucketName = buildBucketName(bucketName);
fileKey = resolveFileKey(bucketName, fileKey);
try {
bucketManager.stat(bucketName, fileKey);
return true;
} catch (QiniuException e) {
if (e.code() == 612)
return false;
throw new JeesuiteBaseException(e.code(), e.getMessage());
}
}
Aggregations