ThrowInvalidJSONException() private static method

private static ThrowInvalidJSONException ( ) : void
return void
Esempio n. 1
0
 private static void CallSafely(Request request, string payload, WriteResponse writeResponse, Func <Request, JSONValue, JSONValue> method)
 {
     try
     {
         JSONValue jsonValue = (JSONValue)((string)null);
         if (payload.Trim().Length == 0)
         {
             jsonValue = new JSONValue();
         }
         else
         {
             try
             {
                 jsonValue = new JSONParser(request.Payload).Parse();
             }
             catch (JSONParseException ex)
             {
                 Handler.ThrowInvalidJSONException();
             }
         }
         writeResponse(HttpStatusCode.Ok, method(request, jsonValue).ToString());
     }
     catch (JSONTypeException ex)
     {
         Handler.ThrowInvalidJSONException();
     }
     catch (KeyNotFoundException ex)
     {
         Handler.RespondWithException(writeResponse, new RestRequestException()
         {
             HttpStatusCode = HttpStatusCode.BadRequest
         });
     }
     catch (RestRequestException ex)
     {
         Handler.RespondWithException(writeResponse, ex);
     }
     catch (Exception ex)
     {
         Handler.RespondWithException(writeResponse, new RestRequestException()
         {
             HttpStatusCode       = HttpStatusCode.InternalServerError,
             RestErrorString      = "InternalServerError",
             RestErrorDescription = "Caught exception while fulfilling request: " + (object)ex
         });
     }
 }
Esempio n. 2
0
 private static void CallSafely(Request request, string payload, Response writeResponse, Func <Request, JSONValue, JSONValue> method)
 {
     try
     {
         JSONValue arg = null;
         if (payload.Trim().Length == 0)
         {
             arg = default(JSONValue);
         }
         else
         {
             try
             {
                 arg = new JSONParser(request.Payload).Parse();
             }
             catch (JSONParseException)
             {
                 Handler.ThrowInvalidJSONException();
             }
         }
         writeResponse.SimpleResponse(HttpStatusCode.Ok, method(request, arg).ToString());
     }
     catch (JSONTypeException)
     {
         Handler.ThrowInvalidJSONException();
     }
     catch (KeyNotFoundException)
     {
         Handler.RespondWithException(writeResponse, new RestRequestException
         {
             HttpStatusCode = HttpStatusCode.BadRequest
         });
     }
     catch (RestRequestException rre)
     {
         Handler.RespondWithException(writeResponse, rre);
     }
     catch (Exception arg2)
     {
         Handler.RespondWithException(writeResponse, new RestRequestException
         {
             HttpStatusCode       = HttpStatusCode.InternalServerError,
             RestErrorString      = "InternalServerError",
             RestErrorDescription = "Caught exception while fulfilling request: " + arg2
         });
     }
 }