/// <summary>validate value is non-null</summary> /// <typeparam name="T">type of value</typeparam> /// <param name="value">value</param> /// <param name="errorcode">error code to throw if null</param> /// <returns>the non-null value</returns> internal static T NullCheck <T>(T value, InternalError errorcode) where T : class { if (Object.ReferenceEquals(value, null)) { Error.ThrowInternalError(errorcode); } return(value); }
private IActionResult Response <T>(IResponseModel <T> result) where T : class { return(result switch { SuccessResponse <T> _ => Ok(result), NotFoundResponse <T> _ => NotFound(result), BadRequestResponse <T> _ => BadRequest(result), InternalError <T> _ => StatusCode(500, result), _ => NotFound() });
private void OnInternalError(Exception ex) { try { InternalError?.Invoke(this, new ErrorEventArgs(ex)); } catch { // ignored } }
private async Task GenerateInternalErrorResposeAsync(Exception e, HttpContext httpContext) { var internalError = new InternalError() { LogEntryId = Guid.NewGuid(), Exception = IsDevelopmentEnvironment() ? e : null }; logger.LogError(0, e, "{LogEntryId}: Ocorreu um erro não esperado.", internalError.LogEntryId); await GenerateResponse(500, internalError, httpContext); }
public IEnumerable <TaskGridModel> GetTaskGrid() { try { TaskService taskService = new TaskService(); return(taskService.GetTaskGrid()); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public List <ElementModel.Element> GetSessionVisualization(string id) { try { SessionService sessionService = new SessionService(); return(sessionService.GetSessionVisualization(id)); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public IEnumerable <SessionGridModel> GetSessionGrid() { try { SessionService sessionService = new SessionService(); return(sessionService.GetSessionGrid()); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
private static void Datenfehler_Meldung_ausgeben(InternalError error) { Console.WriteLine(@"Kommunikationsfehler: " + error.ErrorInfo); MessageBox.Show( "Bei der Abfrage der Benutzerinformationen meldet der Server: \n" + error.ErrorInfo + "\nBitte entfernen Sie den Chip und bestätigen mit 'OK'.", @"Kommunikationsfehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); }
public List <ElementModel.Element> GetTaskVisualization(string id) { try { TaskService taskService = new TaskService(); return(taskService.GetTaskVisualization(id)); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public async Task <IActionResult> Create(ClientRegisterCommand command) { var result = await _mediator.Send(command); return(result switch { SuccessResponse <ClientResponse> _ => StatusCode(201, result), NotFoundResponse <ClientResponse> _ => NotFound(result), BadRequestResponse <ClientResponse> _ => BadRequest(result), InternalError <ClientResponse> _ => StatusCode(500, result), _ => NotFound() });
public HttpResponseMessage Get() { try { PharoSessionService sessionService = new PharoSessionService(); List <PharoSessionModel> sessionModelCollection = sessionService.GetAll(); return(Request.CreateResponse(HttpStatusCode.OK, sessionModelCollection, "application/json")); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public HttpResponseMessage GetGlobalProjects() { try { ProjectService projectService = new ProjectService(); var projects = projectService.GetDistinctProjects(); return(Request.CreateResponse(HttpStatusCode.OK, projects, "application/json")); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public async Task <int> HandleAsync(Exception exception, HttpContext httpContext) { if (exception is AggregateException) { var aggregateException = exception as AggregateException; foreach (var innerException in aggregateException.InnerExceptions) { await HandleAsync(innerException, httpContext); } } else { if (exception is UnauthorizedAccessException) { _logger.LogInformation("Ocorreu um acesso não autorizado."); var forbidden = new { Key = "Forbidden", Message = "Access to this resource is forbidden." }; return(await FormatResponseAsync(forbidden, httpContext, 403)); } if (exception is CoreException) { _logger.LogInformation(exception, "Ocorreu um erro de negócio."); return(await FormatResponseAsync(exception, httpContext, 400)); } else { Guid logEntryId = Guid.NewGuid(); _logger.LogError(exception, "{LogEntryId}: Ocorreu um erro não esperado.", logEntryId); var internalError = new InternalError() { LogEntryId = logEntryId, Exception = (IsDevelopmentEnvironment() ? exception.GetBaseException() : null) }; return(await FormatResponseAsync(internalError, httpContext, 500)); } } return(httpContext.Response.StatusCode); }
internal static FtInternalException Create(InternalError error, string message = "", [System.Runtime.CompilerServices.CallerMemberName] string memberName = "", [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "", [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0) { string errorMessage = ((int)error).ToString(); if (message.Length > 0) { errorMessage += " (" + message + ")"; } return(new FtInternalException(string.Format(Properties.Resources.InternalExceptionMessage, new object[] { errorMessage, memberName, sourceFilePath, sourceLineNumber }))); }
private async Task <int> GenerateInternalErrorResponseAsync(Exception e, HttpContext httpContext) { Exception exception = e; Guid logEntryId = Guid.NewGuid(); logger.LogError(e, "{LogEntryId}: Ocorreu um erro não esperado.", logEntryId); var internalError = new InternalError() { LogEntryId = logEntryId, Exception = (IsDevelopmentEnvironment() ? exception.GetBaseException() : null) }; await GenerateResponseAsync(internalError, httpContext); return(httpContext.Response.StatusCode); }
public HttpResponseMessage GetSourceCodeisualization(string originalId) { try { VisualizationService visualizationService = new VisualizationService(); var view3dData = visualizationService.GetView3dSourceCode(originalId); var data = new JavaScriptSerializer().Serialize(view3dData); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(data, Encoding.UTF8, "application/json"); return(response); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public HttpResponseMessage GetView3UserFilterVisualization(TaskProjectModel filter) { try { VisualizationService visualizationService = new VisualizationService(); var view3dData = visualizationService.GetView3dUserDataFilter(filter); var data = new JavaScriptSerializer().Serialize(view3dData); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(data, Encoding.UTF8, "application/json"); return(response); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public string Post(PharoSession session) { try { if (session.Id == new Guid("00000000-0000-0000-0000-000000000000")) { return("Post rejected: session.Identifier equal 00000000-0000-0000-0000-000000000000."); } SessionSingleton.Instance.PostSessionList.Enqueue(session); SessionSingleton.Instance.ProcessPosting(); return("Object created or updated!"); } catch (Exception ex) { throw InternalError.ThrowError(ex); } }
public override List <DependencyItem> DetectDependencies(ISpecificObjectStructure spec) { if (spec.CreateSql == null) { return(new List <DependencyItem>()); } var dc = new DepsCollector(); MySQLLexer lexer = new MySQLLexer(new ANTLRReaderStream(new StringReader(spec.CreateSql))); CommonTokenStream tokens = new CommonTokenStream(lexer); MySQLParser parser = new MySQLParser(tokens); parser.find_deps(dc); if (parser.Errors != null) { var err = new InternalError("DAE-00057 Error parsing dependencies:" + parser.Errors); err.Data["sql"] = spec.CreateSql; throw err; } return(spec.BuildDependencyList(dc)); }
public async Task <IActionResult> PutArtist(int artistId, int eventId, DateTime performanceDate) { if (performanceDate == null) { return(BadRequest("Podaj datę występu")); } var result = await _artistManageService.ChangePerfomanceDate(new ArtistChangePerformanceDateRequest { IdArtist = artistId, IdEvent = eventId, PerformanceDate = performanceDate }); return(result switch { SuccessResponse _ => Ok(result), ErrorResponse _ => BadRequest(result), InternalError _ => StatusCode(500, result), _ => NotFound() });
public InternalException(InternalError exceptionType, Exception exception) : this(exceptionType, exception.ToString()) { }
internal static void ThrowInternalError(InternalError value) { throw InternalError(value); }
public async Task <ActionResult <int> > InternalError( [FromForm] InternalErrorModel model, [FromServices] SubmissionManager submissionManager) { if (!ModelState.IsValid) { return(BadRequest()); } var toDisable = JObject.Parse(model.disabled); var kind = toDisable["kind"].Value <string>(); if (kind == "language") { var langid = toDisable["langid"].Value <string>(); var lang = await DbContext.Languages .Where(l => l.ExternalId == langid) .SingleAsync(); lang.AllowJudge = false; DbContext.Languages.Update(lang); DbContext.AuditLogs.Add(new AuditLog { ContestId = model.cid ?? 0, EntityId = lang.LangId, Comment = "internal error created", Resolved = true, Time = DateTimeOffset.Now, Type = AuditLog.TargetType.Contest, UserName = "******", }); Telemetry.TrackDependency( dependencyTypeName: "Language", dependencyName: langid, data: model.description, startTime: DateTimeOffset.Now, duration: TimeSpan.Zero, success: false); } else if (kind == "judgehost") { var hostname = toDisable["hostname"].Value <string>(); var host = await DbContext.JudgeHosts .Where(h => h.ServerName == hostname) .SingleAsync(); host.Active = false; DbContext.JudgeHosts.Update(host); DbContext.AuditLogs.Add(new AuditLog { ContestId = model.cid ?? 0, EntityId = host.ServerId, Comment = "internal error created", Resolved = true, Time = DateTimeOffset.Now, Type = AuditLog.TargetType.Contest, UserName = host.ServerName, }); Telemetry.TrackDependency( dependencyTypeName: "JudgeHost", dependencyName: host.ServerName, data: model.description, startTime: DateTimeOffset.Now, duration: TimeSpan.Zero, success: false); } else if (kind == "problem") { var probid = toDisable["probid"].Value <int>(); var prob = await DbContext.Problems .Where(p => p.ProblemId == probid) .SingleAsync(); prob.AllowJudge = false; DbContext.Problems.Update(prob); DbContext.AuditLogs.Add(new AuditLog { ContestId = model.cid ?? 0, EntityId = probid, Comment = "internal error created", Resolved = true, Time = DateTimeOffset.Now, Type = AuditLog.TargetType.Problem, UserName = "******", }); Telemetry.TrackDependency( dependencyTypeName: "Problem", dependencyName: $"p{probid} - {prob.Title}", data: model.description, startTime: DateTimeOffset.Now, duration: TimeSpan.Zero, success: false); } else { Telemetry.TrackDependency( dependencyTypeName: "Unresolved", dependencyName: kind, data: model.description, startTime: DateTimeOffset.Now, duration: TimeSpan.Zero, success: false); } var ie = new InternalError { JudgehostLog = model.judgehostlog, JudgingId = model.judgingid, ContestId = model.cid, Description = model.description, Disabled = model.disabled, Status = InternalErrorStatus.Open, Time = DateTimeOffset.Now, }; if (model.judgingid.HasValue) { await submissionManager.RejudgeForErrorAsync(model.judgingid.Value); } DbContext.InternalErrors.Add(ie); await DbContext.SaveChangesAsync(); return(ie.ErrorId); }
internal static void ThrowBatchExpectedResponse(InternalError value) { throw InvalidOperation(Strings.Batch_ExpectedResponse((int)value)); }
internal static InvalidOperationException InternalError(InternalError value) { return(InvalidOperation(Strings.Context_InternalError((int)value))); }
public Exception error(string description, params object[] capturedData) { var e = new InternalError(objectize(description), capturedData); W("throwing " + e.Message); return e; }
internal static void ThrowBatchUnexpectedContent(InternalError value) { throw InvalidOperation(Strings.Batch_UnexpectedContent((int)value)); }
void RaiseInternalError(Exception ex) { try { InternalError?.Invoke(this, new ErrorEventArgs(ex)); } catch { } }
public static @string Error(this InternalError e) { return("flate: internal error: " + string(e)); }
private void HandleError(InternalError error) { _navigationService.Navigate("ServerConfiguration", error.ToString()); }
public InternalException(InternalError exceptionType) : base(exceptionType.ToString()) { Error = exceptionType; }
public InternalException(InternalError exceptionType, string exceptionMessage) : base($"{exceptionType}: {exceptionMessage}") { Error = exceptionType; }