解决sonar扫描异味。Define a constant instead of duplicating this literal "{}:{}" 9 times.

This commit is contained in:
刘小平 2024-10-28 15:09:57 +08:00
parent 6685caf5b8
commit 197a52584a

View File

@ -37,6 +37,10 @@ public class MinioS3ClientImpl implements MinioS3Client {
* 分片上传块号名称
*/
private static final String PART_NUMBER = "partNumber";
/**
* 日志打印
*/
private static final String LOG_TEMPLATE = "{}:{}";
private final MinioPlusProperties properties;
@ -65,11 +69,11 @@ public class MinioS3ClientImpl implements MinioS3Client {
return this.getClient().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()).get();
} catch (InsufficientDataException | InternalException | InvalidKeyException | IOException |
NoSuchAlgorithmException | XmlParserException | ExecutionException e) {
log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED);
} catch (InterruptedException e){
Thread.currentThread().interrupt(); // 重新设置中断状态
log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED);
}
}
@ -83,7 +87,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
this.getClient().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
}
} catch (Exception e) {
log.error("{}:{}", MinioPlusErrorCode.MAKE_BUCKET_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.MAKE_BUCKET_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.MAKE_BUCKET_FAILED);
}
}
@ -94,7 +98,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
CreateMultipartUploadResponse createMultipartUploadResponse = this.getClient().createMultipartUpload(bucketName, null, objectName, null, null);
return createMultipartUploadResponse.result().uploadId();
} catch (Exception e) {
log.error("{}:{}", MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.CREATE_MULTIPART_UPLOAD_FAILED);
}
}
@ -139,7 +143,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
} catch (Exception e) {
// 查询分片失败打印日志返回空的分片信息
log.error("{}:{}", MinioPlusErrorCode.LIST_PARTS_FAILED.getMessage(), e.getMessage());
log.error(LOG_TEMPLATE, MinioPlusErrorCode.LIST_PARTS_FAILED.getMessage(), e.getMessage());
}
return listParts;
@ -162,7 +166,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
.extraQueryParams(queryParams)
.build());
} catch (Exception e) {
log.error("{}:{}", MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.CREATE_UPLOAD_URL_FAILED);
}
}
@ -183,7 +187,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
.extraQueryParams(reqParams)
.build());
} catch (Exception e) {
log.error("{}:{}", MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.CREATE_DOWNLOAD_URL_FAILED);
}
}
@ -204,7 +208,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
.extraQueryParams(reqParams)
.build());
} catch (Exception e) {
log.error("{}:{}", MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.CREATE_PREVIEW_URL_FAILED);
}
}
@ -235,7 +239,7 @@ public class MinioS3ClientImpl implements MinioS3Client {
throw new MinioPlusException(MinioPlusErrorCode.WRITE_FAILED);
} catch (InterruptedException e){
Thread.currentThread().interrupt(); // 重新设置中断状态
log.error("{}:{}", MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
log.error(LOG_TEMPLATE, MinioPlusErrorCode.BUCKET_EXISTS_FAILED.getMessage(), e.getMessage(), e);
throw new MinioPlusException(MinioPlusErrorCode.BUCKET_EXISTS_FAILED);
}