mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Add generated error code to exceptions
This commit is contained in:
@@ -8,6 +8,8 @@ import static java.util.stream.Collectors.joining;
|
||||
|
||||
public class AlreadyExistsException extends RuntimeException implements ExceptionWithContext {
|
||||
|
||||
private static final String CODE = "FtR7UznKU1";
|
||||
|
||||
private final List<ContextEntry> context;
|
||||
|
||||
public AlreadyExistsException(ModelObject object) {
|
||||
@@ -27,6 +29,11 @@ public class AlreadyExistsException extends RuntimeException implements Exceptio
|
||||
return unmodifiableList(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
|
||||
private static String createMessage(List<ContextEntry> context) {
|
||||
return context.stream()
|
||||
.map(c -> c.getType().toLowerCase() + " with id " + c.getId())
|
||||
|
||||
@@ -7,6 +7,9 @@ import static java.util.Collections.unmodifiableList;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
public class ConcurrentModificationException extends RuntimeException implements ExceptionWithContext {
|
||||
|
||||
private static final String CODE = "2wR7UzpPG1";
|
||||
|
||||
private final List<ContextEntry> context;
|
||||
|
||||
public ConcurrentModificationException(Class type, String id) {
|
||||
@@ -26,6 +29,11 @@ public class ConcurrentModificationException extends RuntimeException implements
|
||||
return unmodifiableList(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
|
||||
private static String createMessage(List<ContextEntry> context) {
|
||||
return context.stream()
|
||||
.map(c -> c.getType().toLowerCase() + " with id " + c.getId())
|
||||
|
||||
@@ -6,4 +6,6 @@ public interface ExceptionWithContext {
|
||||
List<ContextEntry> getContext();
|
||||
|
||||
String getMessage();
|
||||
|
||||
String getCode();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import static java.util.stream.Collectors.joining;
|
||||
|
||||
public class NotFoundException extends RuntimeException implements ExceptionWithContext {
|
||||
|
||||
private static final String CODE = "AGR7UzkhA1";
|
||||
|
||||
private final List<ContextEntry> context;
|
||||
|
||||
public NotFoundException(Class type, String id) {
|
||||
@@ -35,6 +37,11 @@ public class NotFoundException extends RuntimeException implements ExceptionWith
|
||||
return unmodifiableList(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return CODE;
|
||||
}
|
||||
|
||||
private static String createMessage(List<ContextEntry> context) {
|
||||
return context.stream()
|
||||
.map(c -> c.getType().toLowerCase() + " with id " + c.getId())
|
||||
|
||||
@@ -30,6 +30,6 @@ public class ErrorDto {
|
||||
}
|
||||
|
||||
public static ErrorDto from(ExceptionWithContext exception) {
|
||||
return new ErrorDto(MDC.get("transaction_id"), "todo", exception.getContext(), exception.getMessage());
|
||||
return new ErrorDto(MDC.get("transaction_id"), exception.getCode(), exception.getContext(), exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user