private void PopulateResponse(IOwinContext context, MgiExceptionVm resp, HttpStatusCode statusCode = HttpStatusCode.BadRequest) { var jsonObject = JsonProcessor.SerializeObject(resp, camelCase: true); var vmByteArray = Encoding.ASCII.GetBytes(jsonObject); context.Response.Body.Write(vmByteArray, 0, vmByteArray.Length); context.Response.StatusCode = (int)statusCode; context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); }
private static void ProcessGenericException(HttpActionExecutedContext context) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.ServicesException, ErrorString = LocalizationKeys.InternalServerError }; context.Response = context.Request.CreateResponse( HttpStatusCode.InternalServerError, resp ); }
private void ProcessInvalidDeviceException(HttpActionExecutedContext context) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.InvalidDevice, ErrorCode = ((InvalidDeviceException)context.Exception).ErrorCode, ErrorString = ((InvalidDeviceException)context.Exception).ErrorString }; context.Response = context.Request.CreateResponse( HttpStatusCode.Forbidden, resp); }
private static void ProcessTransactionalLimitsException(HttpActionExecutedContext context) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.TransactionalLimitsExceeded, ErrorCode = ((TransactionalLimitsException)context.Exception).ErrorCode, ErrorString = ((TransactionalLimitsException)context.Exception).ErrorString }; context.Response = context.Request.CreateResponse( HttpStatusCode.Forbidden, resp); }
private static void ProcessTrainingModeException(HttpActionExecutedContext context) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.ServicesException, ErrorString = ((TrainingModeException)context.Exception).ErrorString }; context.Response = context.Request.CreateResponse( HttpStatusCode.BadRequest, resp ); }
private static void ProcessArgumentException(HttpActionExecutedContext context) { var exc = (ArgumentException)context.Exception; var errorString = $"Argument exception for {exc.Message}"; var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.ArgumentException, ErrorCode = 400, ErrorString = errorString }; context.Response = context.Request.CreateResponse( HttpStatusCode.BadRequest, resp); }
private static void ProcessPrincipalException(HttpActionExecutedContext context) { var exception = (PrincipalException)context.Exception; var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.PrincipalException, ErrorCode = exception.Code, ErrorString = context.Exception.Message }; context.Response = context.Request.CreateResponse( exception.StatusCode, resp); }
private void ProcessPrincipalException(IOwinContext context, PrincipalException ex) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.PrincipalException, ErrorCode = ex.Code, ErrorString = GetTranslation(context, ex.ErrorMessage) }; // * IMPORTANT * InternalDetails property is for server side logging only, it may contain sensitive information and should // NEVER be mapped to the vm. if (!string.IsNullOrWhiteSpace(ex.InternalDetails)) { logger.Error(ex.InternalDetails); } PopulateResponse(context, resp, ex.StatusCode); }
private static void ProcessFieldException(HttpActionExecutedContext context) { var resp = new MgiExceptionVm { ExceptionType = MgiExceptionType.AgentConnect, ErrorCode = ((FieldException)context.Exception).ErrorCode, ErrorString = ((FieldException)context.Exception).ErrorString, SubErrorCode = ((FieldException)context.Exception).SubErrorCode, OffendingField = ((FieldException)context.Exception).OffendingField, TimeStamp = ((FieldException)context.Exception).TimeStamp, DetailString = ((FieldException)context.Exception).DetailString, }; context.Response = context.Request.CreateResponse( HttpStatusCode.BadRequest, resp ); }