Search in sources :

Example 1 with AbstractCharonException

use of org.wso2.charon3.core.exceptions.AbstractCharonException in project charon by wso2.

the class JSONEncoder method encodeSCIMException.

/*
     * encode scim exceptions
     * @param exception
     * @return
     */
public String encodeSCIMException(AbstractCharonException exception) {
    // outer most json object
    JSONObject rootErrorObject = new JSONObject();
    // JSON Object containing the error code and error message
    JSONObject errorObject = new JSONObject();
    try {
        // construct error object with details in the exception
        errorObject.put(ResponseCodeConstants.SCHEMAS, exception.getSchemas());
        if (exception instanceof BadRequestException) {
            errorObject.put(ResponseCodeConstants.SCIM_TYPE, ((BadRequestException) (exception)).getScimType());
        }
        errorObject.put(ResponseCodeConstants.DETAIL, String.valueOf(exception.getDetail()));
        errorObject.put(ResponseCodeConstants.STATUS, String.valueOf(exception.getStatus()));
        // construct the full json obj.
        rootErrorObject = errorObject;
    } catch (JSONException e) {
        // usually errors occur rarely when encoding exceptions. and no need to pass them to clients.
        // sufficient to log them in server side back end.
        logger.error("SCIMException encoding error");
    }
    return rootErrorObject.toString();
}
Also used : JSONObject(org.json.JSONObject) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONException(org.json.JSONException)

Aggregations

JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)1