/// <summary> /// Returns an error response to the client from a callback. Code /// should exit after this call. /// </summary> /// <param name="ErrorMessage"></param> public void WriteErrorResponse(string errorMessage, string stackTrace) { CallbackException Error = new CallbackException(); Error.message = errorMessage; Error.isCallbackError = true; Error.stackTrace = stackTrace; JSONSerializer Serializer = new JSONSerializer(SupportedJsonParserTypes.JavaScriptSerializer); string result = Serializer.Serialize(Error); if (!string.IsNullOrEmpty(JsonPMethod)) { result = JsonPMethod + "( " + result + " );"; } HttpResponse Response = HttpContext.Current.Response; Response.ContentType = WebResources.STR_JsonContentType; Response.TrySkipIisCustomErrors = true; // override status code but only if it wasn't set already if (Response.StatusCode == 200) { Response.StatusCode = 500; } Response.Write(result); Response.End(); }
/// <summary> /// Returns an error response to the client from a callback. Code /// should exit after this call. /// </summary> /// <param name="ErrorMessage"></param> public void WriteErrorResponse(string errorMessage, string stackTrace) { CallbackException Error = new CallbackException(); Error.message = errorMessage; Error.isCallbackError = true; Error.stackTrace = stackTrace; JSONSerializer Serializer = new JSONSerializer(); string result = null; SerializationUtils.SerializeObject(Error, out result); HttpResponse Response = HttpContext.Current.Response; Response.ContentType = WebResources.STR_XmlContentType; Response.TrySkipIisCustomErrors = true; if (Response.StatusCode == 200) { Response.StatusCode = 500; } Response.Write(result); //HttpContext.Current.ApplicationInstance.CompleteRequest(); Response.End(); }
public CallbackErrorResponseMessage(CallbackException ex, bool allowExceptionDetail = false) : this((Exception)ex, allowExceptionDetail) { isError = true; statusCode = ex.StatusCode; }
public CallbackErrorResponseMessage(CallbackException ex, bool allowExceptionDetail = false) : this((Exception) ex, allowExceptionDetail) { isError = true; statusCode = ex.StatusCode; }
/// <summary> /// Returns an error response to the client from a callback. Code /// should exit after this call. /// </summary> /// <param name="ErrorMessage"></param> public void WriteErrorResponse(string errorMessage, string stackTrace) { CallbackException Error = new CallbackException(); Error.message = errorMessage; Error.isCallbackError = true; Error.stackTrace = stackTrace; JSONSerializer Serializer = new JSONSerializer(); string result = null; SerializationUtils.SerializeObject(Error, out result); HttpResponse Response = HttpContext.Current.Response; Response.ContentType = WebResources.STR_XmlContentType; Response.TrySkipIisCustomErrors = true; if (Response.StatusCode == 200) Response.StatusCode = 500; Response.Write(result); //HttpContext.Current.ApplicationInstance.CompleteRequest(); Response.End(); }
protected ActionResult ExceptionResult(string message) { Response.StatusCode = 500; CallbackException exception = new CallbackException(message); exception.IsError = true; // return result based on ?Format= return ApiResult(exception); }
protected ActionResult ExceptionResult(Exception ex) { Response.StatusCode = 500; CallbackException exception = new CallbackException(ex.GetBaseException().Message); //if (HttpContext.IsDebuggingEnabled) // exception.StackTrace = ex.StackTrace; exception.IsError = true; // return result based on ?Format= return ApiResult(exception); }
/// <summary> /// Ensure that exceptions are returned in the API format /// Excpetion is rendered as a Callback Exception /// </summary> /// <param name="filterContext"></param> protected override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); // only handle API results here: Format must be set // otherwise fall through and return if (string.IsNullOrEmpty(Format)) return; Response.StatusCode = 500; CallbackException exception = new CallbackException(filterContext.Exception.Message); //if (HttpContext.IsDebuggingEnabled) // exception.StackTrace = filterContext.Exception.StackTrace; exception.IsError = true; filterContext.Result = ApiResult(exception); filterContext.ExceptionHandled = true; }
/// <summary> /// Returns an error response to the client from a callback. Code /// should exit after this call. /// </summary> /// <param name="ErrorMessage"></param> public void WriteErrorResponse(string errorMessage, string stackTrace) { CallbackException Error = new CallbackException(); Error.message = errorMessage; Error.isCallbackError = true; Error.stackTrace = stackTrace; JSONSerializer Serializer = new JSONSerializer( SupportedJsonParserTypes.JavaScriptSerializer); string result = Serializer.Serialize(Error); if (!string.IsNullOrEmpty(JsonPMethod)) result = JsonPMethod + "( " + result + " );"; HttpResponse Response = HttpContext.Current.Response; Response.ContentType = WebResources.STR_JsonContentType; Response.TrySkipIisCustomErrors = true; // override status code but only if it wasn't set already if (Response.StatusCode == 200) Response.StatusCode = 500; Response.Write(result); Response.End(); }