|
@@ -273,7 +273,7 @@ namespace JsonRpcLite.Network
|
|
|
if (string.IsNullOrEmpty(serviceName))
|
|
|
{
|
|
|
Logger.WriteWarning($"Service for request: {requestPath} not found.");
|
|
|
- throw new HttpException((int) HttpStatusCode.ServiceUnavailable, "Service does not exist.");
|
|
|
+ throw new HttpException((int)HttpStatusCode.ServiceUnavailable, "Service does not exist.");
|
|
|
}
|
|
|
|
|
|
if (httpMethod == "get")
|
|
@@ -289,7 +289,7 @@ namespace JsonRpcLite.Network
|
|
|
if (!router.ServiceExists(serviceName))
|
|
|
{
|
|
|
Logger.WriteWarning($"Service for request: {requestPath} not found.");
|
|
|
- throw new HttpException((int) HttpStatusCode.ServiceUnavailable,$"Service [{serviceName}] does not exist.");
|
|
|
+ throw new HttpException((int)HttpStatusCode.ServiceUnavailable, $"Service [{serviceName}] does not exist.");
|
|
|
}
|
|
|
|
|
|
if (smdRequest)
|
|
@@ -308,12 +308,12 @@ namespace JsonRpcLite.Network
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- throw new HttpException((int) HttpStatusCode.InternalServerError, ex.Message);
|
|
|
+ throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- throw new HttpException((int) HttpStatusCode.NotFound,$"Resource for {requestPath} does not exist.");
|
|
|
+ throw new HttpException((int)HttpStatusCode.NotFound, $"Resource for {requestPath} does not exist.");
|
|
|
}
|
|
|
}
|
|
|
else if (httpMethod == "post")
|
|
@@ -321,7 +321,7 @@ namespace JsonRpcLite.Network
|
|
|
if (!router.ServiceExists(serviceName))
|
|
|
{
|
|
|
Logger.WriteWarning($"Service for request: {requestPath} not found.");
|
|
|
- throw new ServerErrorException("Service does not exist.",$"Service [{serviceName}] does not exist.");
|
|
|
+ throw new ServerErrorException("Service does not exist.", $"Service [{serviceName}] does not exist.");
|
|
|
}
|
|
|
|
|
|
try
|
|
@@ -340,9 +340,14 @@ namespace JsonRpcLite.Network
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- throw new HttpException((int) HttpStatusCode.MethodNotAllowed, $"Invalid http-method:{httpMethod}");
|
|
|
+ throw new HttpException((int)HttpStatusCode.MethodNotAllowed, $"Invalid http-method:{httpMethod}");
|
|
|
}
|
|
|
}
|
|
|
+ catch (RpcException rpcException)
|
|
|
+ {
|
|
|
+ var response = new JsonRpcResponse();
|
|
|
+ response.WriteResult(rpcException);
|
|
|
+ }
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Logger.WriteError($"Handle request {requestPath} error: {ex.Message}");
|
|
@@ -353,18 +358,10 @@ namespace JsonRpcLite.Network
|
|
|
else
|
|
|
{
|
|
|
var response = new JsonRpcResponse();
|
|
|
- if (ex is RpcException rpcException)
|
|
|
- {
|
|
|
- response.WriteResult(rpcException);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var serverError =
|
|
|
- new InternalErrorException($"Handle request {requestPath} error: {ex.Message}");
|
|
|
- response.WriteResult(serverError);
|
|
|
- }
|
|
|
-
|
|
|
- await WriteRpcResponsesAsync(context, new[] {response}, cancellationToken).ConfigureAwait(false);
|
|
|
+ var serverError =
|
|
|
+ new InternalErrorException($"Handle request {requestPath} error: {ex.Message}");
|
|
|
+ response.WriteResult(serverError);
|
|
|
+ await WriteRpcResponsesAsync(context, new[] { response }, cancellationToken).ConfigureAwait(false);
|
|
|
}
|
|
|
}
|
|
|
finally
|