Skip to content

Commit f4c5549

Browse files
Update Client Exception Handler
1 parent e91cf69 commit f4c5549

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

vcell-apiclient/src/main/java/org/vcell/api/client/ExceptionHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package org.vcell.api.client;
22

3-
import org.vcell.restclient.CustomObjectMapper;
4-
import com.fasterxml.jackson.core.JsonProcessingException;
53
import org.apache.logging.log4j.LogManager;
64
import org.apache.logging.log4j.Logger;
5+
import org.vcell.restclient.CustomObjectMapper;
6+
import com.fasterxml.jackson.core.JsonProcessingException;
77
import org.vcell.restclient.ApiException;
88
import org.vcell.restclient.model.VCellHTTPError;
99
import org.vcell.util.DataAccessException;
1010
import org.vcell.util.ObjectNotFoundException;
1111
import org.vcell.util.PermissionException;
1212

1313
public class ExceptionHandler {
14-
14+
private static final Logger logger = LogManager.getLogger(ExceptionHandler.class);
15+
1516
protected static Exception getProperException(ApiException e){
1617
int httpCode = e.getCode();
1718
String message = e.getResponseBody() == null ? e.getMessage() : e.getResponseBody();
@@ -47,8 +48,9 @@ protected static Exception getProperException(ApiException e){
4748
/**
4849
* Throws data access or runtime exception from ApiException
4950
*/
50-
public static void onlyDataAccessException(ApiException e) throws DataAccessException, ObjectNotFoundException, PermissionException {
51+
public static void onlyDataAccessOrPermissionException(ApiException e) throws DataAccessException, ObjectNotFoundException, PermissionException {
5152
Exception exception = getProperException(e);
53+
logger.error(exception);
5254
if (exception instanceof ObjectNotFoundException onf) {
5355
throw onf;
5456
} if (exception instanceof DataAccessException de){

vcell-apiclient/src/main/java/org/vcell/api/messaging/LocalDataSetControllerMessaging.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ExternalDataIdentifier saveFieldData(FieldData fieldData) throws DataAcce
6969
DtoModelTransforms.fieldDataToDTO(fieldData)
7070
);
7171
} catch (ApiException e) {
72-
ExceptionHandler.onlyDataAccessException(e);
72+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
7373
}
7474
return new ExternalDataIdentifier(new KeyValue(results.getFieldDataKey()), new User(vCellApiClient.getCachedVCellUserName(), null), results.getFieldDataName());
7575
}
@@ -79,7 +79,7 @@ public cbit.vcell.field.io.FieldDataShape getFieldDataShape(KeyValue externalDat
7979
try {
8080
shape = vCellApiClient.getFieldDataApi().getShapeFromID(externalDataIdentifierKey.toString());
8181
} catch (ApiException e) {
82-
ExceptionHandler.onlyDataAccessException(e);
82+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
8383
}
8484
return DtoModelTransforms.DTOToFieldDataShape(shape);
8585
}
@@ -91,7 +91,7 @@ public ExternalDataIdentifier analyzeAndCreateFieldData(FieldDataSpec fieldDataS
9191
DtoModelTransforms.extentToDTO(fieldDataSpec.extent), DtoModelTransforms.iSizeToDTO(fieldDataSpec.iSize), fieldDataSpec.channelNames, fieldDataSpec.times, fieldDataSpec.annotation,
9292
DtoModelTransforms.originToDTO(fieldDataSpec.origin));
9393
} catch (ApiException e) {
94-
ExceptionHandler.onlyDataAccessException(e);
94+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
9595
}
9696
return new ExternalDataIdentifier(new KeyValue(savedResults.getFieldDataKey()), fieldDataSpec.owner, savedResults.getFieldDataName());
9797
}

vcell-apiclient/src/main/java/org/vcell/api/messaging/LocalUserMetaDbServerMessaging.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
package org.vcell.api.messaging;
1212

13-
import cbit.vcell.biomodel.BioModelMetaData;
1413
import cbit.vcell.field.FieldDataAllDBEntries;
15-
import cbit.vcell.mathmodel.MathModelMetaData;
1614
import cbit.vcell.message.server.bootstrap.client.RemoteProxyException;
1715
import cbit.vcell.message.server.bootstrap.client.RpcDbServerProxy;
1816
import cbit.vcell.message.server.bootstrap.client.RpcSender;
@@ -106,7 +104,7 @@ public void deleteBioModel(org.vcell.util.document.KeyValue key) throws DataAcce
106104
try {
107105
vCellApiClient.getBioModelApi().deleteBioModel(key.toString());
108106
} catch (ApiException e) {
109-
ExceptionHandler.onlyDataAccessException(e);
107+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
110108
}
111109
}
112110

@@ -115,7 +113,7 @@ public FieldDataAllDBEntries getAllFieldDataIDs() throws DataAccessException {
115113
try {
116114
fieldDataReferences = vCellApiClient.getFieldDataApi().getAllIDs();
117115
} catch (ApiException e) {
118-
ExceptionHandler.onlyDataAccessException(e);
116+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
119117
}
120118
return DtoModelTransforms.fieldDataReferencesToDBResults(fieldDataReferences);
121119
}
@@ -178,7 +176,7 @@ public void deleteMathModel(org.vcell.util.document.KeyValue key) throws DataAcc
178176
if (lg.isTraceEnabled()) lg.trace("LocalUserMetaDbServerMessaging.deleteMathModel(Key="+key+")");
179177
vCellApiClient.getMathModelApi().deleteMathModel(key.toString());
180178
} catch (ApiException e) {
181-
ExceptionHandler.onlyDataAccessException(e);
179+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
182180
throw new RuntimeException("Expected error handler to throw an error.", e);
183181
}
184182
}
@@ -280,7 +278,7 @@ public org.vcell.util.document.BioModelInfo getBioModelInfo(org.vcell.util.docum
280278
BioModelSummary context = vCellApiClient.getBioModelApi().getBioModelSummary(bioModelKey.toString());
281279
return DtoModelTransforms.bioModelContextToBioModelInfo(context);
282280
} catch (ApiException e) {
283-
ExceptionHandler.onlyDataAccessException(e);
281+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
284282
throw new RuntimeException("Exception handler did not throw an exception.");
285283
}
286284
}
@@ -297,7 +295,7 @@ public org.vcell.util.document.BioModelInfo[] getBioModelInfos(boolean bAll) thr
297295
}
298296
return infos;
299297
} catch (ApiException e) {
300-
ExceptionHandler.onlyDataAccessException(e);
298+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
301299
throw new RuntimeException("Exception handler did not throw an exception.");
302300
}
303301
}
@@ -312,7 +310,7 @@ public BigString getBioModelXML(KeyValue bioModelKey) throws DataAccessException
312310
if (lg.isTraceEnabled()) lg.trace("LocalUserMetaDbServerMessaging.getBioModelXML(key="+bioModelKey+")");
313311
return new BigString(vCellApiClient.getBioModelApi().getBioModelVCML(bioModelKey.toString()));
314312
} catch (ApiException e) {
315-
ExceptionHandler.onlyDataAccessException(e);
313+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
316314
throw new RuntimeException("Exception handler did not throw an error.", e);
317315
}
318316
}
@@ -427,12 +425,12 @@ public BigString getGeometryXML(KeyValue geometryKey) throws DataAccessException
427425
}
428426

429427

430-
public MathModelInfo getMathModelInfo(KeyValue key) throws DataAccessException, ObjectNotFoundException, RemoteProxyException {
428+
public MathModelInfo getMathModelInfo(KeyValue key) throws DataAccessException, ObjectNotFoundException {
431429
try {
432430
MathModelSummary summary = vCellApiClient.getMathModelApi().getSummary(key.toString());
433431
return DtoModelTransforms.mathModelContextToMathModel(summary);
434432
} catch (ApiException e) {
435-
ExceptionHandler.onlyDataAccessException(e);
433+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
436434
throw new RuntimeException("Exception handler did not throw an exception.");
437435
}
438436
}
@@ -448,7 +446,7 @@ public org.vcell.util.document.MathModelInfo[] getMathModelInfos(boolean bAll) t
448446
}
449447
return modelInfos;
450448
} catch (ApiException e) {
451-
ExceptionHandler.onlyDataAccessException(e);
449+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
452450
throw new RuntimeException("Exception handler did not throw an error.", e);
453451
}
454452
}
@@ -844,7 +842,7 @@ public BigString saveBioModel(BigString bioModelXML, String independentSims[]) t
844842
independentSims == null ? null : Arrays.asList(independentSims)
845843
);
846844
} catch (ApiException e) {
847-
ExceptionHandler.onlyDataAccessException(e);
845+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
848846
}
849847
return new BigString(savedBioModelXML);
850848
}
@@ -865,7 +863,7 @@ public BigString saveBioModelAs(BigString bioModelXML, String newName, String in
865863
independentSims == null ? null : Arrays.asList(independentSims)
866864
);
867865
} catch (ApiException e) {
868-
ExceptionHandler.onlyDataAccessException(e);
866+
ExceptionHandler.onlyDataAccessOrPermissionException(e);
869867
}
870868
return new BigString(savedBioModelXML);
871869

0 commit comments

Comments
 (0)