Skip to content

Commit ce9419c

Browse files
authored
absent concept set exception is handled now (1897) (#1898)
Co-authored-by: Sergey Suvorov <[email protected]>
1 parent 54f04ed commit ce9419c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/main/java/org/ohdsi/webapi/util/GenericExceptionMapper.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
import javax.ws.rs.ext.Provider;
3333
import java.io.PrintWriter;
3434
import java.io.StringWriter;
35+
import java.lang.reflect.InvocationTargetException;
36+
import java.lang.reflect.UndeclaredThrowableException;
37+
import java.util.Objects;
3538

3639
/**
3740
*
@@ -66,6 +69,20 @@ public Response toResponse(Throwable ex) {
6669
ex = new RuntimeException(ex.getMessage());
6770
} else if (ex instanceof ConceptNotExistException) {
6871
responseStatus = Status.BAD_REQUEST;
72+
} else if (ex instanceof UndeclaredThrowableException) {
73+
Throwable throwable = getThrowable((UndeclaredThrowableException)ex);
74+
if (Objects.nonNull(throwable)) {
75+
if (throwable instanceof ConceptNotExistException) {
76+
responseStatus = Status.BAD_REQUEST;
77+
ex = throwable;
78+
} else {
79+
responseStatus = Status.INTERNAL_SERVER_ERROR;
80+
ex = new RuntimeException("An exception occurred: " + ex.getClass().getName());
81+
}
82+
} else {
83+
responseStatus = Status.INTERNAL_SERVER_ERROR;
84+
ex = new RuntimeException("An exception occurred: " + ex.getClass().getName());
85+
}
6986
} else {
7087
responseStatus = Status.INTERNAL_SERVER_ERROR;
7188
// Create new message to prevent sending error information to client
@@ -79,4 +96,12 @@ public Response toResponse(Throwable ex) {
7996
.type(MediaType.APPLICATION_JSON)
8097
.build();
8198
}
99+
100+
private Throwable getThrowable(UndeclaredThrowableException ex) {
101+
if (Objects.nonNull(ex.getUndeclaredThrowable()) && ex.getUndeclaredThrowable() instanceof InvocationTargetException) {
102+
InvocationTargetException ite = (InvocationTargetException) ex.getUndeclaredThrowable();
103+
return ite.getTargetException();
104+
}
105+
return null;
106+
}
82107
}

0 commit comments

Comments
 (0)