Created
August 13, 2013 09:58
-
-
Save codescribler/6219683 to your computer and use it in GitHub Desktop.
A small collection of code for capturing client side javascript errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ErrorController : Controller | |
{ | |
[HttpPost] | |
public JsonResult Record(ErrorInputModel model) | |
{ | |
var ex = new ClientErrorException(model.ToString()); | |
var signal = ErrorSignal.FromCurrentContext(); | |
signal.Raise(ex); | |
var result = new JsonResult {Data = JsonConvert.SerializeObject(new {Success = true})}; | |
return result; | |
} | |
} | |
public class ErrorInputModel | |
{ | |
public string ErrorText { get; set; } | |
public string Url { get; set; } | |
public int? LineNumber { get; set; } | |
public override string ToString() | |
{ | |
return string.Format("Error Text: {0}, Url: {1}, Line Number: {2}", this.ErrorText, this.Url, | |
(LineNumber.HasValue ? LineNumber.Value.ToString() : "Unkown")); | |
} | |
} | |
public class ClientErrorException : Exception | |
{ | |
public ClientErrorException(string message) : base(message){} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment