Created
May 1, 2014 14:50
-
-
Save mgroves/5f907e1b0ab273309433 to your computer and use it in GitHub Desktop.
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 override void OnInvoke(MethodInterceptionArgs args) | |
| { | |
| try | |
| { | |
| args.Proceed(); | |
| } | |
| catch (SqlException ex) | |
| { | |
| var obj = (ServiceBase) args.Instance; | |
| if (ex.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) | |
| obj.AddValidationError("This item can't be deleted because it is still used by other items."); | |
| else | |
| { | |
| obj.AddValidationError(GetErrorMessage(ex)); | |
| if (!IsThisSite.RunningLocally) | |
| ex.ToExceptionless().Submit(); | |
| } | |
| ErrorReturn(args); | |
| } | |
| catch (NotImplementedException) | |
| { | |
| // if something's not implemented, just throw it up | |
| throw; | |
| } | |
| catch (Exception ex) | |
| { | |
| if (!IsThisSite.RunningLocally) | |
| ex.ToExceptionless().Submit(); | |
| var obj = (ServiceBase)args.Instance; | |
| obj.AddValidationError(GetErrorMessage(ex)); | |
| ErrorReturn(args); | |
| } | |
| } | |
| private string GetErrorMessage(Exception ex) | |
| { | |
| if(IsThisSite.RunningLocally) | |
| return "There was an error. Please try again later. (" + ex.Message + "), (" + ex.GetType().FullName + ")"; | |
| return "There was an error. Please try again later."; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment