DocumentRepository error handling

Hello all,

I am using a customized document repository to check if some documents are duplicates before persisting them, just like it is described in this documentation tutorial. This works well except for the detail that validating Composed Document Model will rollback the transaction and display this error message :

I would like to make the form error more user friendly and remove the second part “JSON-RPC Request failed...”.
So far, I had a look at the ProblemReporter to see if it would help give more control on the error message, but it did not.
Is anyone aware of a way to hide the “JSON-RPC Request failed...” part of the error ?

Just in case, this would be the code of my create method (custom exception thrown in 'checkNameIsUnique) :

public void create(DataServicesDocument dataServicesDocument) {
		mdCustomValidator.checkNameIsUnique(dataServicesDocument, getAllDocumentsByModel(dataServicesDocument.getModelName()));
		defaultDocumentRepository.create(dataServicesDocument);
	}

Moin @arthur-typed-river,

please have a look at the following discourse thread: Relationship Upper Limit Reached error message / validation - #4 by jlemsky

I think the discussion and provided solution in there, might already help you.

Thank you for your answer !
Unfortunately, I also had a try with this approach which was not a solution because there isn’t a suitable error message to overwrite.
I’m hoping the requirement ticket you created will fix this in the future :slight_smile:

Moin @arthur-typed-river,

could you please try to override the resource key for rpc.operation.previous.error, this is the Exception key, which handles the second error.

String RPC_OPERATION_PREVIOUS_FAILED_KEY = "rpc.operation.previous.error";

And is thrown in com.mgmtp.a12.dataservices.rpc.internal.JsonRpcOperationDispatcher:

    @Override
	protected Object getHandler(String serviceName) {
		if (OperationContextHolder.isFailed()) {
			throw new OperationFailedException(RPC_OPERATION_PREVIOUS_FAILED_KEY, "Previous operation failed.");
		}
		return operations.get(serviceName);
	}

You should be able to override it in your localization resources file as follows:

    rpc: {
        operation: {
            previous: {
                error: {
                    title: "<YOUR TITLE>",
                    description: "<YOUR DESCRIPTION>"
                }
            }
        }
    }

:warning: But again, this might override other messages in your application, this error message is not CDM-specific.

The A12 ticket has been created to provide a solution. Once done, the information will be shared with you here.
The Discourse team