コード例 #1
0
ファイル: rpcController.cs プロジェクト: s7loves/pesta
        private Object getErrorJson(ResponseItem responseItem)
        {
            Dictionary<String, Object> error = new Dictionary<String, Object>();
            error.Add("code", responseItem.getErrorCode());

            String message = errorTitles[responseItem.getErrorCode()];
            if (message == null)
            {
                message = responseItem.getErrorMessage();
            }
            else
            {
                if (!string.IsNullOrEmpty(responseItem.getErrorMessage()))
                {
                    message += ": " + responseItem.getErrorMessage();
                }
            }

            if (!string.IsNullOrEmpty(message))
            {
                error.Add("message", message);
            }

            if (responseItem.getResponse() != null)
            {
                error.Add("data", responseItem.getResponse());
            }

            return error;
        }
コード例 #2
0
ファイル: restController.cs プロジェクト: s7loves/pesta
 protected override void sendError(HttpResponse servletResponse, ResponseItem responseItem)
 {
     int errorCode = responseItem.getErrorCode();
     if (errorCode < 0)
     {
         // Map JSON-RPC error codes into HTTP error codes as best we can
         // TODO: Augment the error message (if missing) with a default
         switch (errorCode)
         {
             case -32700:
             case -32602:
             case -32600:
                 // Parse error, invalid params, and invalid request 
                 errorCode = (int)HttpStatusCode.BadRequest;
                 break;
             case -32601:
                 // Procedure doesn't exist
                 errorCode = (int)HttpStatusCode.NotImplemented;
                 break;
             case -32603:
             default:
                 // Internal server error, or any application-defined error
                 errorCode = (int)HttpStatusCode.InternalServerError;
                 break;
         }
     }
     servletResponse.ContentType = ContentTypes.OUTPUT_TEXT_CONTENT_TYPE;
     servletResponse.StatusCode = errorCode;
     servletResponse.StatusDescription = responseItem.getErrorMessage();
     servletResponse.Output.Write(responseItem.getErrorMessage());
 }