/// <summary> /// Invokes the specified context. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public async Task InvokeAsync(HttpContext httpContext) { try { await _next(httpContext); } catch (GeneralException exception) { _logger.LogError(exception, exception.Message); await HandleExceptionAsync(httpContext, exception); } catch (System.Exception exception) when(IsBusinessException(exception)) { _logger.LogError(exception, exception.Message); var businessException = new BusinessException(exception.Message, exception); await HandleExceptionAsync(httpContext, businessException); } catch (System.Exception exception) { _logger.LogError(exception, exception.Message); var generalException = new GeneralException("An unhandled exception has occurred.", exception); await HandleExceptionAsync(httpContext, generalException); } }
/// <summary> /// Handles all exceptions that are thrown by COLID and could not be treated. /// </summary> /// <param name="httpContext">the context of request.</param> /// <param name="generalException">New COLID exception that is passed on to the user.</param> /// <param name="exception">The untreated expcetion.</param> /// <returns></returns> private async Task HandleExceptionAsync(HttpContext httpContext, GeneralException generalException) { httpContext.Response.ContentType = MediaTypeNames.Application.Json; httpContext.Response.StatusCode = generalException.Code; generalException.RequestId = httpContext.TraceIdentifier; generalException.ApplicationId = _applicationId; if (generalException.InnerException != null) { generalException.Data.Add("type", generalException.InnerException.GetType().Name); generalException.Data.Add("message", generalException.InnerException.Message); } if (generalException.Code == 500) { var additionalInformation = new Dictionary <string, object>() { { "Exception", generalException.InnerException }, // Necessary because all properties of the general exception base classes are ignored during normal serialization. { "ExceptionType", generalException.Type }, // Important for filtering in kibana { "TraceIdentifier", httpContext.TraceIdentifier } }; if (_env.IsDevelopment() || _env.IsEnvironment("Local") || _env.IsEnvironment("OnPrem") || _env.IsEnvironment("Testing")) { if (generalException?.InnerException?.Message != null) { additionalInformation.Add("ExceptionDetails", generalException.InnerException.Message); } } _generalLogService.Error(generalException, generalException.Message, additionalInformation); } await httpContext.Response.WriteAsync(JsonConvert.SerializeObject(generalException, _jsonSerializerSettings)); }
/// <summary> /// Invokes the specified context. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public async Task InvokeAsync(HttpContext httpContext) { try { await _next(httpContext); } catch (GeneralException exception) { await HandleExceptionAsync(httpContext, exception); } catch (ArgumentException exception) { var businessException = new BusinessException(exception.Message, exception); await HandleExceptionAsync(httpContext, businessException); } catch (ElasticsearchClientException exception) { var technicalException = new TechnicalException("An error has occurred in the request against elasticsearch", exception); technicalException.Data.Add("additionalMessage", exception.Message); await HandleExceptionAsync(httpContext, technicalException); } catch (Exception exception) { var generalException = new GeneralException("An unhandled exception has occurred.", exception); await HandleExceptionAsync(httpContext, generalException); } }
/// <summary> /// Commits the transaction. /// </summary> public override void Commit() { if (Committed) { return; } lock (_sync) { try { DbContext.SaveChanges(); } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine; } } var fail = new GeneralException(msg, dbEx); //Debug.WriteLine(fail.Message, fail); throw fail; } } Committed = true; }
/// <summary> /// Handles all exceptions that are thrown by COLID and could not be treated. /// </summary> /// <param name="httpContext">the context of request.</param> /// <param name="generalException">New COLID exception that is passed on to the user.</param> /// <param name="exception">The untreated expcetion.</param> /// <returns></returns> private async Task HandleExceptionAsync(HttpContext httpContext, GeneralException generalException) { httpContext.Response.ContentType = MediaTypeNames.Application.Json; httpContext.Response.StatusCode = generalException.Code; generalException.RequestId = httpContext.TraceIdentifier; generalException.ApplicationId = _applicationId; await httpContext.Response.WriteAsync(JsonConvert.SerializeObject(generalException, _jsonSerializerSettings)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.mainView); AppDomain.CurrentDomain.UnhandledException += (s, e) => { Task.Run(async() => await GeneralException.HandleGeneralException(s, e)); }; TaskScheduler.UnobservedTaskException += (s, e) => { Task.Run(async() => await GeneralException.HandleGeneralException(s, e)); }; }
public void InvalidFunction() { var exception = new GeneralException(""); var observedExitCode = ExitCodeUtilities.ShowException(exception); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); var exception2 = new Exception(); observedExitCode = ExitCodeUtilities.ShowException(exception2); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); var exception3 = new InvalidOperationException(); observedExitCode = ExitCodeUtilities.ShowException(exception3); Assert.Equal((int)ExitCodes.InvalidFunction, observedExitCode); }
/// <summary> /// Handles the AfterInstall event of the InstallerClass1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="InstallEventArgs" /> instance containing the event data.</param> private void InstallerClass1_AfterInstall(object sender, InstallEventArgs e) { try { //MessageBox.Show("Stat InstallerClass1_AfterInstall Started "); try { //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Started "); string fileName = "app_config.xml"; string fileName1 = "app_db_config.xml"; string sourcePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string targetPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString() + @"\PHS\AgentInteractionDesktop"; if (!System.IO.Directory.Exists(targetPath)) { //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Creating Directory : " + targetPath); System.IO.Directory.CreateDirectory(targetPath); //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Created Directory : " + targetPath); } string sourceFile = System.IO.Path.Combine(sourcePath, fileName); string destFile = System.IO.Path.Combine(targetPath, fileName); System.IO.File.Copy(sourceFile, destFile, true); //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Sourcefile : "+sourceFile+" , Destinations File : "+destFile ); sourceFile = System.IO.Path.Combine(sourcePath, fileName1); destFile = System.IO.Path.Combine(targetPath, fileName1); System.IO.File.Copy(sourceFile, destFile, true); //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Sourcefile : " + sourceFile + " , Destinations File : " + destFile); //MessageBox.Show("InstallerClass1_AfterInstall : Copying XML Files : Ended"); } catch (Exception GeneralException) { logger.Error("InstallerClass1_AfterInstall Method: Error occured while after installing the setup " + GeneralException.ToString()); //MessageBox.Show("Exception InstallerClass1_AfterInstall : " + GeneralException.Message); } //Commented on 06/07/2015, by Elango.T for Preventing Application start in OS boot and Run for the first time //Directory.SetCurrentDirectory(Path.GetDirectoryName // (Assembly.GetExecutingAssembly().Location)); //Process.Start(Path.GetDirectoryName( // Assembly.GetExecutingAssembly().Location) + "\\StatTickerFive.exe"); //Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); //Assembly curAssembly = Assembly.GetExecutingAssembly(); //key.SetValue(curAssembly.GetName().Name, curAssembly.Location); //MessageBox.Show("InstallerClass1_AfterInstall Ended "); } catch (Exception GeneralException) { MessageBox.Show(" Exception occurred after Installing StatTickerFive : " + GeneralException.InnerException != null ? GeneralException.InnerException.Message : GeneralException.Message); } }
/// <summary> /// Displays GeneralException /// </summary> /// <param name="ex"></param> private static void ShowGeneralException(GeneralException ex) { string msg = Util.GetComprehensiveExceptionMessage(ex); ShowError(msg, false); }