Skip to content

Commit 1af367a

Browse files
Update Server Exceptions to Include the Original Exception
1 parent ec39285 commit 1af367a

9 files changed

Lines changed: 30 additions & 32 deletions

File tree

vcell-rest/src/main/java/org/vcell/restq/db/UserRestDB.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public enum UserRequirement{
5454
ALLOW_ANONYMOUS,
5555
REQUIRE_USER
5656
}
57-
public User getUserFromIdentity(SecurityIdentity securityIdentity, UserRequirement allowAnonymous) throws NotAuthenticatedWebException, PermissionWebException {
57+
public User getUserFromIdentity(SecurityIdentity securityIdentity, UserRequirement allowAnonymous) throws NotAuthenticatedWebException, PermissionWebException, DataAccessWebException {
5858
List<UserIdentity> userIdentities = getUserIdentities(securityIdentity);
5959
if (userIdentities == null || userIdentities.isEmpty()){
6060
if (allowAnonymous == UserRequirement.ALLOW_ANONYMOUS){
@@ -70,7 +70,7 @@ public User getUserFromIdentity(SecurityIdentity securityIdentity, UserRequireme
7070
}
7171

7272
// TODO: add some short-lived caching here to avoid repeated database calls
73-
public List<UserIdentity> getUserIdentities(SecurityIdentity securityIdentity) throws NotAuthenticatedWebException {
73+
public List<UserIdentity> getUserIdentities(SecurityIdentity securityIdentity) throws NotAuthenticatedWebException, DataAccessWebException {
7474
if (securityIdentity.isAnonymous()){
7575
return null;
7676
}
@@ -88,8 +88,10 @@ public List<UserIdentity> getUserIdentities(SecurityIdentity securityIdentity) t
8888
}
8989
try {
9090
return adminDBTopLevel.getUserIdentitiesFromSubjectAndIssuer(subject, issuer, true);
91-
} catch (SQLException | DataAccessException e) {
92-
throw new WebApplicationException("database error while retrieving user identity: "+e.getMessage(), e, HTTP.BAD_REQUEST);
91+
} catch (DataAccessException e){
92+
throw new DataAccessWebException(e.getMessage(), e);
93+
} catch (SQLException e) {
94+
throw new RuntimeWebException("database error while retrieving user identity: ", e);
9395
}
9496
}
9597

@@ -125,7 +127,7 @@ public boolean mapUserIdentity(JWTUtils.MagicTokenClaims magicTokenClaims) throw
125127
} catch (DataAccessException e){
126128
throw new DataAccessWebException(e.getMessage(), e);
127129
} catch (SQLException e) {
128-
throw new RuntimeWebException("database error while mapping user identity: "+e.getMessage(), e);
130+
throw new RuntimeWebException("database error while mapping user identity", e);
129131
}
130132
}
131133

@@ -171,7 +173,7 @@ public boolean mapUserIdentity(SecurityIdentity securityIdentity, UsersResource.
171173
} catch (DataAccessException e){
172174
throw new DataAccessWebException(e.getMessage(), e);
173175
} catch (SQLException e) {
174-
throw new RuntimeWebException("database error while mapping user identity: "+e.getMessage(), e);
176+
throw new RuntimeWebException("database error while mapping user identity", e);
175177
}
176178
}
177179

@@ -229,7 +231,7 @@ public boolean unmapUserIdentity(SecurityIdentity securityIdentity, String userN
229231
} catch (DataAccessException e){
230232
throw new DataAccessWebException(e.getMessage(), e);
231233
} catch (SQLException e) {
232-
throw new RuntimeWebException("database error while mapping user identity: "+e.getMessage(), e);
234+
throw new RuntimeWebException("database error while mapping user identity", e);
233235
}
234236
}
235237

@@ -280,7 +282,7 @@ public UserInfo getUserInfo(String userID) throws NotFoundWebException, DataAcce
280282
} catch (DataAccessException e){
281283
throw new DataAccessWebException(e.getMessage(), e);
282284
} catch (SQLException e){
283-
throw new RuntimeWebException(e);
285+
throw new RuntimeWebException("Database Error" ,e);
284286
}
285287
}
286288
}

vcell-rest/src/main/java/org/vcell/restq/errors/exceptions/RuntimeWebException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,4 @@ public class RuntimeWebException extends RuntimeException{
99
public RuntimeWebException(String message, Exception e){
1010
super(message, e);
1111
}
12-
13-
public RuntimeWebException(Exception e){
14-
super(e);
15-
}
1612
}

vcell-rest/src/main/java/org/vcell/restq/handlers/AdminResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Response getUsage() throws DataAccessWebException, NotAuthenticatedWebExc
7878
htmlWorker.parse(new StringReader(htmlString));
7979
document.close();
8080
} catch (Exception e) {
81-
throw new WebApplicationException("Error while generating PDF", e);
81+
throw new WebApplicationException("Error while generating PDF: " + e.getMessage(), e);
8282
}
8383
};
8484
return Response
@@ -87,7 +87,7 @@ public Response getUsage() throws DataAccessWebException, NotAuthenticatedWebExc
8787
.build();
8888
} catch (SQLException | DataAccessException e) {
8989
lg.error("database error", e);
90-
throw new DataAccessWebException("database error", e);
90+
throw new DataAccessWebException(e.getMessage(), e);
9191
}
9292
}
9393
}

vcell-rest/src/main/java/org/vcell/restq/handlers/BioModelResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public BioModel getBioModelInfo(@PathParam("bioModelID") String bioModelID) thro
5252
BioModelRep bioModelRep = bioModelRestDB.getBioModelRep(new KeyValue(bioModelID), vcellUser);
5353
return BioModel.fromBioModelRep(bioModelRep);
5454
}catch (ObjectNotFoundException e) {
55-
throw new NotFoundWebException("BioModel not found.", e);
55+
throw new NotFoundWebException(e.getMessage(), e);
5656
} catch (DataAccessException e){
5757
throw new DataAccessWebException(e.getMessage(), e);
5858
}
@@ -70,9 +70,9 @@ public String getBioModelVCML(@PathParam("bioModelID") String bioModelID) throws
7070
try {
7171
return bioModelRestDB.getBioModel(vcellUser, new KeyValue(bioModelID));
7272
}catch (ObjectNotFoundException e) {
73-
throw new NotFoundWebException("BioModel not found", e);
73+
throw new NotFoundWebException(e.getMessage(), e);
7474
} catch (DataAccessException e) {
75-
throw new DataAccessWebException("Can't Access BioModel", e);
75+
throw new DataAccessWebException(e.getMessage(), e);
7676
}
7777
}
7878

@@ -136,7 +136,7 @@ public String save(@Valid SaveBioModel saveBioModel) throws DataAccessWebExcepti
136136
} catch (DataAccessException e) {
137137
throw new DataAccessWebException(e.getMessage(), e);
138138
} catch (XmlParseException e){
139-
throw new UnprocessableContentWebException("Couldn't parse the BioModel.", e);
139+
throw new UnprocessableContentWebException(e.getMessage(), e);
140140
}
141141
}
142142

vcell-rest/src/main/java/org/vcell/restq/handlers/FieldData/FieldDataResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public FieldDataSavedResults analyzeAndCreateFieldData(@RestForm @PartType(Media
133133
} catch (DataAccessException e){
134134
throw new DataAccessWebException(e.getMessage(), e);
135135
} catch (ImageException | IOException e) {
136-
throw new WebApplicationException("Can't create new field data: " + e.getMessage(), e, HTTP.INTERNAL_SERVER_ERROR);
136+
throw new RuntimeWebException("Can't create new field data: " + e.getMessage(), e);
137137
}
138138
}
139139

@@ -159,7 +159,7 @@ public FieldDataSavedResults createFromFileWithDefaults(@RestForm @PartType(Medi
159159
} catch (DataAccessException e){
160160
throw new DataAccessWebException(e.getMessage(), e);
161161
} catch (ImageException | IOException e) {
162-
throw new WebApplicationException("Can't create new field data: " + e.getMessage(), e, HTTP.INTERNAL_SERVER_ERROR);
162+
throw new RuntimeWebException("Can't create new field data: " + e.getMessage(), e);
163163
}
164164
}
165165

@@ -182,7 +182,7 @@ public FieldData analyzeFile(@RestForm File file, @RestForm String fileName) thr
182182
} catch (DataAccessException e){
183183
throw new DataAccessWebException(e.getMessage(), e);
184184
} catch (ImageException e) {
185-
throw new WebApplicationException("Can't create new field data file", e, HTTP.INTERNAL_SERVER_ERROR);
185+
throw new RuntimeWebException("Can't create new field data file: " + e.getMessage(), e);
186186
}
187187
}
188188

@@ -206,7 +206,7 @@ public FieldDataSavedResults createNewFieldDataFromSpecification(FieldData saveF
206206
} catch (DataAccessException e){
207207
throw new DataAccessWebException(e.getMessage(), e);
208208
} catch (ImageException | IOException e) {
209-
throw new WebApplicationException(e.getMessage(), e, HTTP.INTERNAL_SERVER_ERROR);
209+
throw new RuntimeWebException(e.getMessage(), e);
210210
}
211211
return fieldDataSavedResults;
212212
}

vcell-rest/src/main/java/org/vcell/restq/handlers/PublicationResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Publication get_by_id(@PathParam("id") Long publicationID) throws Permiss
4646
} catch (PermissionException e){
4747
throw new PermissionWebException(e.getMessage(), e);
4848
} catch (SQLException e){
49-
throw new RuntimeWebException(e);
49+
throw new RuntimeWebException(e.getMessage(), e);
5050
} catch (DataAccessException e) {
5151
throw new DataAccessWebException("failed to retrieve publications from VCell Database : " + e.getMessage(), e);
5252
}

vcell-rest/src/main/java/org/vcell/restq/handlers/SimulationResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ArrayList<StatusMessage> startSimulation(@PathParam("simID") String simID
4949
} catch (DataAccessException e){
5050
throw new DataAccessWebException(e.getMessage(), e);
5151
} catch (SQLException e) {
52-
throw new RuntimeWebException(e);
52+
throw new RuntimeWebException("Database Exception", e);
5353
}
5454
}
5555

@@ -64,7 +64,7 @@ public ArrayList<StatusMessage> stopSimulation(@PathParam("simID") String simID)
6464
} catch (DataAccessException e){
6565
throw new DataAccessWebException(e.getMessage(), e);
6666
} catch (SQLException | VCMessagingException e) {
67-
throw new RuntimeWebException(e);
67+
throw new RuntimeWebException(e.getMessage(), e);
6868
}
6969
}
7070

@@ -80,7 +80,7 @@ public SimulationStatusPersistentRecord getSimulationStatus(@PathParam("simID")
8080
} catch (DataAccessException e){
8181
throw new DataAccessWebException(e.getMessage(), e);
8282
} catch (SQLException e) {
83-
throw new RuntimeWebException(e);
83+
throw new RuntimeWebException(e.getMessage(), e);
8484
}
8585
}
8686

vcell-rest/src/main/java/org/vcell/restq/handlers/SolverResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public File retrieveFiniteVolumeInputFromSBMLSpatial(@RestForm File sbmlFile,
6767
} catch (PropertyVetoException | MappingException | SolverException | ExpressionException e){
6868
throw new UnprocessableContentWebException(e.getMessage(), e);
6969
} catch (VCLoggerException | IOException e){
70-
throw new RuntimeWebException("Error processing spatial model", e);
70+
throw new RuntimeWebException("Error processing spatial model: " + e.getMessage(), e);
7171
} finally {
7272
if (workingDir != null && zipFile != null){
7373
for (File file: workingDir.listFiles()){
@@ -125,7 +125,7 @@ public File retrieveFiniteVolumeInputFromVCML(@RestForm File vcmlFile, @RestForm
125125
} catch (XmlParseException | MappingException | SolverException | ExpressionException e){
126126
throw new UnprocessableContentWebException("Error processing spatial model: "+e.getMessage(), e);
127127
} catch (IOException e){
128-
throw new RuntimeWebException("IO Error on server.", e);
128+
throw new RuntimeWebException("IO Error on server: " + e.getMessage(), e);
129129
} finally {
130130
if (workingDir != null && zipFile != null){
131131
for (File file: workingDir.listFiles()){

vcell-rest/src/main/java/org/vcell/restq/handlers/UsersResource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ email, requestorSubject, requestorIssuer, new User(userInfo.userid, userInfo.id)
122122
try {
123123
magicJWT = JWTUtils.createMagicLinkJWT(magicTokenClaims, JWTUtils.MAGIC_LINK_DURATION_SECONDS);
124124
} catch (JoseException e) {
125-
throw new RuntimeWebException(e);
125+
throw new RuntimeWebException(e.getMessage(), e);
126126
}
127127
// create URL with same host as this server, but a query parameter 'magic' with text magicJWT
128128
URI uri = uriInfo.getAbsolutePath();
@@ -220,12 +220,12 @@ public boolean unmapUser(String userName) throws DataAccessWebException, NotAuth
220220
@APIResponse(responseCode = "200", description = "Successful, returning the identity"),
221221
})
222222
@Produces(MediaType.APPLICATION_JSON)
223-
public UserIdentityJSONSafe getIdentity() throws NotAuthenticatedWebException {
223+
public UserIdentityJSONSafe getIdentity() throws NotAuthenticatedWebException, ConflictWebException, DataAccessWebException {
224224
List<UserIdentity> userIdentities = userRestDB.getUserIdentities(securityIdentity);
225225
if (userIdentities.isEmpty()){
226226
return UserIdentityJSONSafe.noIdentity();
227227
} else if (userIdentities.size() > 1){
228-
throw new WebApplicationException("Multiple identities found for user", Response.Status.INTERNAL_SERVER_ERROR);
228+
throw new ConflictWebException("Multiple identities found for user");
229229
} else {
230230
return UserIdentityJSONSafe.fromUserIdentity(userIdentities.get(0));
231231
}
@@ -279,7 +279,7 @@ public void forgotLegacyPassword(@QueryParam("userID") String userID) throws Dat
279279
} catch (DataAccessException e){
280280
throw new DataAccessWebException(e.getMessage(), e);
281281
} catch (SQLException e) {
282-
throw new RuntimeWebException(e);
282+
throw new RuntimeWebException(e.getMessage(), e);
283283
}
284284
}
285285

0 commit comments

Comments
 (0)