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