Beispiel #1
0
        private static Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            var code = HttpStatusCode.InternalServerError; // 500 if unexpected

            //if (exception is NotFoundException) code = HttpStatusCode.NotFound;
            //else if (exception is UnauthorizedException) code = HttpStatusCode.Unauthorized;
            //else if (exception is CustomException) code = HttpStatusCode.BadRequest;

            // Using RFC 7807 response for error formatting
            // https://tools.ietf.org/html/rfc7807
            var problem = new ProblemDetails
            {
                Type     = "https://yourdomain.com/errors/internal-server-error",
                Title    = "Internal Server Error",
                Detail   = exception.Message,
                Instance = "",
                Status   = (int)code
            };

            //var result = JsonSerializer.ToString(problem);

            context.Response.ContentType = "application/problem+json";
            context.Response.StatusCode  = (int)code;

            //  return context.Response.WriteAsync(result);
            return(context.Response.WriteAsync(problem.ToString()));
        }
        public static async Task <string> OnGetRelay(string vURL)
        {
            await Task.Run(() => { });

            try
            {
                HttpClient client = new HttpClient();

                var msg = client.GetStringAsync(vURL).Result;

                return(msg);
            }
            catch (Exception ex)
            {
                ProblemDetails res = new ProblemDetails {
                    Status = 500, Title = ex.Message
                };

                return(res.ToString());
            }
        }