예제 #1
0
        public static ExecutionError DefaultFormatError(ExecutionOptions options, Exception exception)
        {
            var rootCause = exception.GetBaseException();
            var message   = rootCause.Message;
            var error     = new ExecutionError()
            {
                Message = message
            };

            EnrichWithErrorCode(error, rootCause);

            if (options.IncludeExceptionDetails)
            {
                EnrichWithStackTrace(error, rootCause);
            }

            if (!(exception is QueryExecutionException graphQLError))
            {
                return(error);
            }

            error.Locations = graphQLError.Nodes?
                              .Where(n => n.Location != null)
                              .Select(n => n.Location.Value)
                              .ToList();

            error.Path = graphQLError.Path?.Segments.ToList();

            if (graphQLError.Extensions != null)
            {
                foreach (var extension in graphQLError.Extensions)
                {
                    error.Extend(extension.Key, extension.Value);
                }
            }

            return(error);
        }
예제 #2
0
 public static void EnrichWithStackTrace(ExecutionError error, Exception exception)
 {
     error.Extend("stacktrace", exception.ToString());
 }