extend by another exception

This commit is contained in:
HWienhold 2023-08-02 19:13:32 +02:00
parent a9f2f4df67
commit bb794ee923
3 changed files with 28 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.yaml.snakeyaml.constructor.DuplicateKeyException;
import com.indu.exceptionservice.response.ErrorMessage;
import com.indu.exceptionservice.service.ExceptionService;
@ -16,7 +17,7 @@ import lombok.RequiredArgsConstructor;
public class CustomExceptionHandler {
private final ExceptionService service;
@ExceptionHandler(value = {NameAlreadyTakenException.class, ConflictException.class})
@ExceptionHandler(value = {NameAlreadyTakenException.class, ConflictException.class, DuplicateKeyException.class})
public ResponseEntity<ErrorMessage> handleNameNotUnique(Exception e, WebRequest request) {
return service.handleException(e, HttpStatus.CONFLICT);
}
@ -25,4 +26,9 @@ public class CustomExceptionHandler {
public ResponseEntity<ErrorMessage> handleGeneralException(Exception e, WebRequest request) {
return service.handleException(e, HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(value = {ObjectWithUniqueFieldNotFoundException.class} )
public ResponseEntity<ErrorMessage> handleNotFoundException(Exception e, WebRequest request) {
return service.handleException(e, HttpStatus.NOT_FOUND);
}
}

View File

@ -0,0 +1,16 @@
package com.indu.exceptionservice.exception;
public class ObjectWithUniqueFieldNotFoundException extends RuntimeException {
private static final long serialVersionUID = 8345143863898967852L;
public ObjectWithUniqueFieldNotFoundException(String field, String value, String what) {
super("Object " + what + " with " + field + " = " + value + " not found");
}
public ObjectWithUniqueFieldNotFoundException(String msg) {
super(msg);
}
}

View File

@ -2,6 +2,7 @@ package com.indu.workflowtemplateservice.model;
import java.util.List;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
@ -23,10 +24,12 @@ public class WorkflowTemplate {
private String id;
@NotNull
private char identiferPrefix;
@NotNull
@Indexed(unique = true)
private String name; // unique identifier for sequence
private List<TaskTemplateData> tasks;
private int subflowStart;
@DBRef
private WorkflowTemplate subWorkflow;
private List<WorkflowTemplate> subWorkflow;
}