src/main/java/js/servlet/AppServlet.java
protected static void sendError(RequestContext context, Throwable throwable) throws IOException {
		if (throwable instanceof InvocationException && throwable.getCause() != null) {
			throwable = throwable.getCause();
		}
		if (throwable instanceof InvocationTargetException) {
			throwable = ((InvocationTargetException) throwable).getTargetException();
		}
		if (throwable instanceof BusinessException) {
			// business constrains exception is generated by user space code and sent to client using HTTP response
			// status 400 - HttpServletResponse.SC_BAD_REQUEST, as JSON serialized object
			log.debug("Send business constrain exception |%d|.", ((BusinessException) throwable).getErrorCode());
			sendJsonObject(context, throwable, HttpServletResponse.SC_BAD_REQUEST);
		} else {
			dumpError(context, throwable);
			sendJsonObject(context, new RemoteException(throwable), HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}
	}
protected static void sendError(RequestContext context, Throwable throwable) throws IOException {
		if (throwable instanceof InvocationException && throwable.getCause() != null) {
			throwable = throwable.getCause();
		}
		if (throwable instanceof InvocationTargetException) {
			throwable = ((InvocationTargetException) throwable).getTargetException();
		}
		if (throwable instanceof BusinessException) {
			// business constrains exception is generated by user space code and sent to client using HTTP response
			// status 400 - HttpServletResponse.SC_BAD_REQUEST, as JSON serialized object
			log.debug("Send business constrain exception |%d|.", ((BusinessException) throwable).getErrorCode());
			sendJsonObject(context, throwable, HttpServletResponse.SC_BAD_REQUEST);
		} else {
			dumpError(context, throwable);
			sendJsonObject(context, new RemoteException(throwable), HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}
	}
Send server error response with given exception serialized JSON. This utility method dumps stack trace and request
context to application logger and send back throwable object. Response is encoded JSON and status code is
{@link HttpServletResponse#SC_INTERNAL_SERVER_ERROR}. If given exception argument is {@link InvocationException} or
{@link InvocationTargetException} extract the cause.
<p>
There is a special case for {@link BusinessException}. This exception signals broken business constrain and is send back
also as JSON object but with status code {@link HttpServletResponse#SC_BAD_REQUEST}. Also does not dump exception stack
trace or request context.

@param context current request context,
@param throwable exception describing server error.
@throws IOException if writing to response stream fails.