try 블록에서 큰 파일 크기에 대한 유효성 검사를 마쳤습니다. 오류를 다시 던지고 정적 제약 조건의 다른 속성에 대한 null 값을 확인하고 그 오류를 던집니다.이중 오류 제거 방법 groovy
첫 번째 오류를 반환 한 후 흐름을 중지하는 방법은 무엇입니까? 여기
이 큰 파일 크기 오류 후 코드static constraints = {
applicationName(blank: false, size: 1..25)
applicationShortName(blank: false, size: 1..10)
applicationImage(nullable: false, maxSize: MAX_SIZE)
contentProviderId (
validator: {
if (it == 0) {
return ['notSelected']
}
}
)
customErrorMessage (
validator: {
if ("fileToBig".equals(it)) {
return ['fileToBig']
}
}
)
}
try {
CommonsMultipartFile file = request.getFile('applicationImageUrl');
logger.debug("POSTPROCESS: is file empty=${file.isEmpty()}")
if(!file.isEmpty()) {
try {
-- other logic
}
catch (Exception ex) {
logger.warn("Failed to upload file - improper file type", ex)
return [];
}
logger.debug("Getting new image file")
try {
-- logic
if (file.size <= MAX_SIZE) {
-- logic
} else {
customErrorMessage = "fileToBig"; (ERROR FOR BIG FILE SIZE)
}
} catch (Exception e) {
logger.warn("Failed to upload file", e)
customErrorMessage = "fileToBig";
}
} else {
logger.debug("File was empty. Will check if there is a file in submission")
if (submission.applicationImage != null && submission.applicationImage != []) {
logger.debug("submission contains applicationImage=${submission.applicationImage}")
this.applicationImage = submission.applicationImage;
}
}
} catch (Exception e) {
this.errors.reject("error","An error occured when uploading file. Please try again.");
logger.error("Failed to upload file", e);
return [];
}
--logic
if (application != null) { //Application already exists!
submission.applicationId = application.id;
return [next: 10];
}
return [];
}
이며, 응용 프로그램 이미지가 설정되어 있지 않은, 그 던지는 응용 프로그램 이미지 널 오류뿐만 아니라 ...
나는 이것을 수행 할 방법을 모른다. 이 제약 조건을 위반하면 유효성 검사를 중단하려는 이유를 설명 할 수 있습니까? 아마도 나는 당신의 목표를 달성하기위한 또 다른 방법을 제안 할 수 있습니다. –
수정 된 질문을 확인하십시오 ... 제발 그것을 – Techie