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();
}
Aggregations