Exemple #1
0
        public async Task <IHttpActionResult> Send(ApiRequest apiRequest)
        {
            try
            {
                var typeInformation = new RequestTypeInformation(apiRequest);

                var result = JsonConvert.DeserializeObject(apiRequest.RequestJson, typeInformation.RequestType,
                                                           new EnumerationConverter());

                var response = await mediator.SendAsync(result, typeInformation.ResponseType);

                return(Ok(response));
            }
            catch (AuthenticationException ex)
            {
                logger.Error(ex, "Authentication error");
                return(this.StatusCode(HttpStatusCode.Unauthorized, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (SecurityException ex)
            {
                logger.Error(ex, "Authorization error");
                return(this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (RequestAuthorizationException ex)
            {
                logger.Error(ex, "Request authorization error");
                return(this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unhandled error");
                throw;
            }
        }
        public async Task<IHttpActionResult> Send(ApiRequest apiRequest)
        {
            try
            {
                var typeInformation = new RequestTypeInformation(apiRequest);

                var result = JsonConvert.DeserializeObject(apiRequest.RequestJson, typeInformation.RequestType,
                    new EnumerationConverter());

                var response = await mediator.SendAsync(result, typeInformation.ResponseType);
                return Ok(response);
            }
            catch (AuthenticationException ex)
            {
                logger.Error(ex, "Authentication error");
                return this.StatusCode(HttpStatusCode.Unauthorized, new HttpError(ex, includeErrorDetail: true));
            }
            catch (SecurityException ex)
            {
                logger.Error(ex, "Authorization error");
                return this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true));
            }
            catch (RequestAuthorizationException ex)
            {
                logger.Error(ex, "Request authorization error");
                return this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Unhandled error");
                throw;
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> Send(ApiRequest apiRequest)
        {
            if (!ModelState.IsValid)
            {
                // We need to check here that the ModelState is valid. Some infrastructury low-level
                // wizardry may have caused the apiRequest parameter to be provided as null.
                // For example, if the JSON request exceeds the maximum request size.
                IEnumerable <string> errorMessages = ModelState.Values
                                                     .SelectMany(v => v.Errors)
                                                     .Select(e => (e.Exception != null) ? e.Exception.Message : e.ErrorMessage);

                string message = string.Join(" ", errorMessages);

                throw new Exception(message);
            }

            var typeInformation = new RequestTypeInformation(apiRequest);

            var result = JsonConvert.DeserializeObject(apiRequest.RequestJson, typeInformation.RequestType);

            try
            {
                var response = await mediator.SendAsync(result, typeInformation.ResponseType);

                response = await roleRequestHandler.HandleAsync(response);

                return(Ok(response));
            }
            catch (AuthenticationException ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return(this.StatusCode(HttpStatusCode.Unauthorized, new HttpError(ex, includeErrorDetail: true)));
            }
            catch (SecurityException ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return(this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true)));
            }
        }
        public async Task<IHttpActionResult> Send(ApiRequest apiRequest)
        {
            if (!ModelState.IsValid)
            {
                // We need to check here that the ModelState is valid. Some infrastructury low-level
                // wizardry may have caused the apiRequest parameter to be provided as null.
                // For example, if the JSON request exceeds the maximum request size.
                IEnumerable<string> errorMessages = ModelState.Values
                    .SelectMany(v => v.Errors)
                    .Select(e => (e.Exception != null) ? e.Exception.Message : e.ErrorMessage);

                string message = string.Join(" ", errorMessages);

                throw new Exception(message);
            }
            
            var typeInformation = new RequestTypeInformation(apiRequest);

            var result = JsonConvert.DeserializeObject(apiRequest.RequestJson, typeInformation.RequestType);

            try
            {
                var response = await mediator.SendAsync(result, typeInformation.ResponseType);
                response = await roleRequestHandler.HandleAsync(response);
                return Ok(response);
            }
            catch (AuthenticationException ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return this.StatusCode(HttpStatusCode.Unauthorized, new HttpError(ex, includeErrorDetail: true));
            }
            catch (SecurityException ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                return this.StatusCode(HttpStatusCode.Forbidden, new HttpError(ex, includeErrorDetail: true));
            }
        }