mirror of
https://gitee.com/wangkang/udf.git
synced 2026-11-05 22:35:30 +00:00
更新异常处理方式
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
cleanup.add_default_serial_version_id=true
|
||||
cleanup.add_generated_serial_version_id=false
|
||||
cleanup.add_missing_annotations=true
|
||||
cleanup.add_missing_deprecated_annotations=true
|
||||
cleanup.add_missing_methods=false
|
||||
cleanup.add_missing_nls_tags=false
|
||||
cleanup.add_missing_override_annotations=true
|
||||
cleanup.add_missing_override_annotations_interface_methods=true
|
||||
cleanup.add_serial_version_id=false
|
||||
cleanup.always_use_blocks=true
|
||||
cleanup.always_use_parentheses_in_expressions=false
|
||||
cleanup.always_use_this_for_non_static_field_access=true
|
||||
cleanup.always_use_this_for_non_static_method_access=true
|
||||
cleanup.convert_functional_interfaces=false
|
||||
cleanup.convert_to_enhanced_for_loop=false
|
||||
cleanup.correct_indentation=false
|
||||
cleanup.format_source_code=false
|
||||
cleanup.format_source_code_changes_only=false
|
||||
cleanup.insert_inferred_type_arguments=false
|
||||
cleanup.make_local_variable_final=true
|
||||
cleanup.make_parameters_final=false
|
||||
cleanup.make_private_fields_final=true
|
||||
cleanup.make_type_abstract_if_missing_method=false
|
||||
cleanup.make_variable_declarations_final=false
|
||||
cleanup.never_use_blocks=false
|
||||
cleanup.never_use_parentheses_in_expressions=true
|
||||
cleanup.organize_imports=true
|
||||
cleanup.qualify_static_field_accesses_with_declaring_class=false
|
||||
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
|
||||
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
|
||||
cleanup.qualify_static_member_accesses_with_declaring_class=true
|
||||
cleanup.qualify_static_method_accesses_with_declaring_class=false
|
||||
cleanup.remove_private_constructors=true
|
||||
cleanup.remove_redundant_type_arguments=false
|
||||
cleanup.remove_trailing_whitespaces=false
|
||||
cleanup.remove_trailing_whitespaces_all=true
|
||||
cleanup.remove_trailing_whitespaces_ignore_empty=false
|
||||
cleanup.remove_unnecessary_casts=true
|
||||
cleanup.remove_unnecessary_nls_tags=true
|
||||
cleanup.remove_unused_imports=true
|
||||
cleanup.remove_unused_local_variables=false
|
||||
cleanup.remove_unused_private_fields=true
|
||||
cleanup.remove_unused_private_members=false
|
||||
cleanup.remove_unused_private_methods=true
|
||||
cleanup.remove_unused_private_types=true
|
||||
cleanup.sort_members=false
|
||||
cleanup.sort_members_all=false
|
||||
cleanup.use_anonymous_class_creation=false
|
||||
cleanup.use_blocks=true
|
||||
cleanup.use_blocks_only_for_return_and_throw=false
|
||||
cleanup.use_lambda=true
|
||||
cleanup.use_parentheses_in_expressions=false
|
||||
cleanup.use_this_for_non_static_field_access=true
|
||||
cleanup.use_this_for_non_static_field_access_only_if_necessary=false
|
||||
cleanup.use_this_for_non_static_method_access=true
|
||||
cleanup.use_this_for_non_static_method_access_only_if_necessary=false
|
||||
cleanup_profile=_eclipse-cs udf-starter-core
|
||||
cleanup_settings_version=2
|
||||
eclipse.preferences.version=1
|
||||
formatter_profile=_eclipse-cs udf-starter-core
|
||||
formatter_settings_version=13
|
||||
+14
-10
@@ -5,8 +5,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.itkk.udf.core.ApplicationConfig;
|
||||
import org.itkk.udf.core.RestResponse;
|
||||
import org.itkk.udf.core.exception.ErrorResult;
|
||||
import org.itkk.udf.core.exception.SystemRuntimeException;
|
||||
import org.itkk.udf.core.exception.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -53,24 +52,29 @@ public class ExceptionHandle extends ResponseEntityExceptionHandler {
|
||||
|
||||
@Override
|
||||
protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) {
|
||||
RestResponse<String> result = new RestResponse<>(status, buildError(ex));
|
||||
//判断是不是rest请求异常
|
||||
if (ex instanceof RestClientResponseException) {
|
||||
HttpStatus localHttpStatus = status;
|
||||
ErrorResult errorResult = this.buildError(ex);
|
||||
if (ex instanceof PermissionException) { //权限异常
|
||||
localHttpStatus = HttpStatus.FORBIDDEN;
|
||||
} else if (ex instanceof AuthException) { //认证异常
|
||||
localHttpStatus = HttpStatus.UNAUTHORIZED;
|
||||
} else if (ex instanceof ParameterValidException) { //参数校验异常
|
||||
localHttpStatus = HttpStatus.BAD_REQUEST;
|
||||
} else if (ex instanceof RestClientResponseException) { //rest请求异常
|
||||
try {
|
||||
//获得子错误
|
||||
RestClientResponseException restClientResponseException = (RestClientResponseException) ex;
|
||||
String data = restClientResponseException.getResponseBodyAsString();
|
||||
if (StringUtils.isNotBlank(data)) {
|
||||
//解析子错误
|
||||
RestResponse<String> child = objectMapper.readValue(data, objectMapper.getTypeFactory().constructParametricType(RestResponse.class, String.class));
|
||||
//设置子错误
|
||||
result.getError().setChild(child);
|
||||
errorResult.setChild(child);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SystemRuntimeException(e);
|
||||
}
|
||||
} else { //未知异常
|
||||
localHttpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
return super.handleExceptionInternal(ex, result, headers, status, request);
|
||||
return super.handleExceptionInternal(ex, new RestResponse<>(status, errorResult), headers, localHttpStatus, request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user