fixed exception handler

This commit is contained in:
Andrey Terentev 2024-05-27 09:34:11 +07:00 committed by Andrey Terentev
parent 6d0409c6c8
commit 0c19050436

View File

@ -14,16 +14,15 @@ public class ExceptionService {
if (exceptionMap != null) return;
exceptionMap = new HashMap<>();
var ref = new Reflections("ru.dragonestia.picker.api.exception");
var ref = new Reflections("ru.dragonestia.picker");
for (var clazz: ref.getTypesAnnotatedWith(ApiException.class)) {
if (!clazz.isNestmateOf(RuntimeException.class)) continue;
exceptionMap.put(clazz.getSimpleName(), clazz);
}
}
public static RuntimeException prepare(String ex, String message) {
try {
System.out.println(exceptionMap);
return (RuntimeException) exceptionMap.getOrDefault(ex, UnknownException.class)
.getConstructor(String.class)
.newInstance(message);