Esempio n. 1
0
        public void CreatingFromException_MapsProperties_FromMostInnerException()
        {
            // Arrange
            const string InnerMessage    = "InnerMessage";
            var          innerException  = new ArgumentException(InnerMessage);
            var          middleException = new ArgumentNullException("MiddleMessage", innerException);
            var          outerException  = new Exception("OuterMessage", middleException);

            // Act
            var actualServerException = ServerException.CreateFromException(outerException);

            // Assert
            Assert.AreEqual(InnerMessage, actualServerException.Message);
            Assert.AreEqual(innerException.GetType().Name, actualServerException.TypeName);
        }
Esempio n. 2
0
        public async Task Invoke(HttpContext httpContext)
        {
            try
            {
                await _next(httpContext);
            }
            catch (Exception exception)
            {
                var response = httpContext.Response;
                response.ContentType = MediaTypeNames.Application.Json;
                response.StatusCode  = (int)HttpStatusCode.InternalServerError;

                var serverException       = ServerException.CreateFromException(exception);
                var serializedServerError = JsonConvert.SerializeObject(serverException);

                await response.WriteAsync(serializedServerError);
            }
        }