Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> RunAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest httpRequest,
            ILogger logger)
        {
            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (httpRequest is null)
            {
                logger.LogError($"{nameof(httpRequest)} is null in SendMessage", httpRequest);
                throw new ArgumentNullException(nameof(httpRequest));
            }

            try
            {
                // Use a real correlation id instead of Guid.NewGuid().ToString()
                var request  = new Request(Guid.NewGuid().ToString(), httpRequest.Body);
                var response = await _sendMessageService
                               .HandleSendMessageAsync(request)
                               .ConfigureAwait(false);

                return(response.AsHttpResponseMessage());
            }
            catch (SoapAdapterException exception)
            {
                // TODO: correlation id?
                logger.LogError(exception, "Error in SendMessage");
                var response = await _errorResponseFactory
                               .CreateAsync($"{exception.ErrorMessage}:{exception.MessageReference}")
                               .ConfigureAwait(false);

                return(response.AsHttpResponseMessage());
            }
#pragma warning disable CA1031 // This is the point where we want to catch unknown exceptions
            catch (Exception exception)
            {
                logger.LogCritical(exception, "Error in SendMessage");
                var response = await _errorResponseFactory
                               .CreateAsync("B2B-900", "Server")
                               .ConfigureAwait(false);

                return(response.AsHttpResponseMessage());

#pragma warning disable CA1031
            }
        }