예제 #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, HttpVerbs.Get, Route =
                             PathSegments.Feedback)] HttpRequest req, ILogger logger)
        {
            try
            {
                var model = _modelFactory.Create(req.Query);

                var result = _validator.Validate(model);
                if (!result.IsValid)
                {
                    return(ErrorsBuilder.BuildBadArgumentError("Feedback Get Request Data contains invalid/missing arguments",
                                                               result.Errors));
                }
                var feedbackData = await _handler.HandleAsync(model);

                return(new OkObjectResult(feedbackData));
            }
            catch (Exception ex)
            {
                //TODO : configure app to log to Azure AppInsights
                if (ex is AggregateException agx)
                {
                    logger.WriteAggregateException(agx);
                }
                else
                {
                    logger.WriteException(ex);
                }
                return(ErrorsBuilder.BuildInternalServerError());
            }
        }
예제 #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, HttpVerbs.Post, Route =
                             PathSegments.Feedback + "/{sessionId:Guid?}")] HttpRequest req, Guid?sessionId, ILogger logger)
        {
            try
            {
                var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var model       = _modelFactory.Create(requestBody, req.Headers, sessionId);

                var result = _validator.Validate(model);
                if (!result.IsValid)
                {
                    return(ErrorsBuilder.BuildBadArgumentError("Feedback Create Request Data contains invalid/missing arguments",
                                                               result.Errors));
                }

                var feedbackDto = await _handler.HandleAsync(model);

                var location = RoutesHelper.BuildFeedbackGetUrl(feedbackDto.Id, req.Host.Value ?? string.Empty, req.IsHttps);
                return(new CreatedResult(location, feedbackDto));
            }
            catch (SessionNotFoundException snfEx)
            {
                return(ErrorsBuilder.BuildNotFoundError(snfEx.Message));
            }
            catch (FeedbackCreateRequestNotAllowedException snfEx)
            {
                return(ErrorsBuilder.BuildNotAllowedError(snfEx.Message));
            }
            catch (Exception ex)
            {
                //TODO : configure app to log to Azure AppInsights
                if (ex is AggregateException agx)
                {
                    logger.WriteAggregateException(agx);
                }
                else
                {
                    logger.WriteException(ex);
                }
                return(ErrorsBuilder.BuildInternalServerError());
            }
        }
예제 #3
0
        private static void HandleErrors(IDictionary <string, object> ret)
        {
            if (ret == null)
            {
                throw new FormatException("Error while parsing RAML");
            }

            var errorsRaw = ret["errors"];

            var errorObjects = errorsRaw as object[];

            if (errorObjects != null && errorObjects.Length != 0)
            {
                var errorsBuilder = new ErrorsBuilder(errorObjects);
                var errors        = errorsBuilder.GetErrors();
                if (errors.Any(e => e.IsWarning == false))
                {
                    throw new FormatException(errorsBuilder.GetMessages());
                }
            }
        }