예제 #1
0
        public static IJsonRpcHandlerBuilder UseSecurityExceptionHandler(this IJsonRpcHandlerBuilder builder)
        {
            return(builder.Use(async(context, next) =>
            {
                try
                {
                    await next();
                }
                catch (Exception exception)
                {
                    var securityException = exception.Unwrap <SecurityException>();
                    if (securityException != null)
                    {
                        // This is wrong:
                        // 1) we are using exceptions for flow control
                        // 2) sematically `SecurityException` means more `Forbidden` than `Unauthorized`
                        // However - this get's the job done and I can't think of any better alternative without
                        // introducing ton of boilerplate code.

                        context.SetResponse(JsonRpcError.UNAUTHORIZED, $"{JsonRpcError.GetMessage(JsonRpcError.UNAUTHORIZED)} - {securityException.Message}");
                    }
                    else
                    {
                        throw;
                    }
                }
            }));
        }
예제 #2
0
 public JsonRpcException(int code, object data = null)
     : base(JsonRpcError.GetMessage(code))
 {
     JsonRpcCode = code;
     JsonRpcData = data;
 }
예제 #3
0
 public JsonRpcResponse(object id, int errorCode, object errorData = null)
     : this(id, errorCode, JsonRpcError.GetMessage(errorCode), errorData : errorData)
 {
 }