Skip to content
This repository was archived by the owner on Jan 2, 2022. It is now read-only.
This repository was archived by the owner on Jan 2, 2022. It is now read-only.

Solution for cross-cutting Exception handling #7

Description

@bernard01

In the context of authentication, I use existing jsonrpc functionality to propagate an exception to the client.

So the application throws org.json.rpc.commons.JsonRpcRemoteException with an application-defined result code value.

jsonrpc takes action in

JsonRpcExecutor#execute(JsonRpcServerTransport transport)

    try {
        JsonElement result = executeMethod(methodName, params);
        resp.add("result", result);
    } catch (Throwable t) {
        LOG.warn("exception occured while executing : " + methodName, t);// #### here
        if (t instanceof JsonRpcRemoteException) {
            sendError(transport, resp, (JsonRpcRemoteException) t);
            return;
        }
        errorCode = JsonRpcErrorCodes.getServerError(1);
        errorMessage = t.getMessage();
        errorData = getStackTrace(t);
        sendError(transport, resp, errorCode, errorMessage, errorData);
        return;
    }

It prints a warning message in the log.

Depending on the severity of the abnormal condition, this message may need to be logged as an error, as a warning, or not logged at all. Currently a NullPointerException is converted into a warning.

Can this be improved? Perhaps JsonRpcRemoteException could have a constructor parameter for the logging level so that the application can control the logging behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions