Catch 2 different types of exception
This commit is contained in:
@ -23,29 +23,23 @@ public class SigningRequestDocumentController implements SigningRequestDocumentA
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> patchSigningRequestDocument(String id, List<PatchOperation> patchOperations) {
|
public ResponseEntity<Void> patchSigningRequestDocument(String id, List<PatchOperation> patchOperations) {
|
||||||
// Fetch the existing document
|
|
||||||
var document = signingRequestDocumentService.getSigningRequestDocument(id);
|
var document = signingRequestDocumentService.getSigningRequestDocument(id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
JsonNode patchNode = objectMapper.valueToTree(patchOperations);
|
||||||
// Serialize patchOperations to JsonNode
|
|
||||||
JsonNode patchNode = mapper.valueToTree(patchOperations);
|
|
||||||
|
|
||||||
// Create JsonPatch from JsonNode
|
|
||||||
JsonPatch jsonPatch = JsonPatch.fromJson(patchNode);
|
JsonPatch jsonPatch = JsonPatch.fromJson(patchNode);
|
||||||
|
|
||||||
// Apply patch to the document's JsonNode
|
JsonNode patchedNode = jsonPatch.apply(objectMapper.convertValue(document, JsonNode.class));
|
||||||
JsonNode patchedNode = jsonPatch.apply(mapper.convertValue(document, JsonNode.class));
|
|
||||||
|
|
||||||
// Convert the patched JsonNode back to SigningRequestDocument
|
SigningRequestDocument patchedDocument = objectMapper.treeToValue(patchedNode, SigningRequestDocument.class);
|
||||||
SigningRequestDocument patchedDocument = mapper.treeToValue(patchedNode, SigningRequestDocument.class);
|
|
||||||
|
|
||||||
// Now, update the document in the service layer
|
|
||||||
signingRequestDocumentService.updateSigningRequestDocument(patchedDocument);
|
signingRequestDocumentService.updateSigningRequestDocument(patchedDocument);
|
||||||
|
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
} catch (IOException | JsonPatchException e) {
|
} catch (JsonPatchException e) {
|
||||||
// Handle exceptions appropriately
|
throw new IllegalArgumentException("Failed to apply patch", e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Failed to apply patch", e);
|
throw new RuntimeException("Failed to apply patch", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user