Browse Source

Fix error formatting.

pull/1039/head
Sebastian 3 years ago
parent
commit
1d22ffe2a6
  1. 4
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLResolver.cs
  2. 35
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ErrorProvider.cs
  3. 5
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ErrorVisitor.cs
  4. 3
      backend/src/Squidex/Config/Web/WebServices.cs

4
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLResolver.cs

@ -55,7 +55,9 @@ public sealed class CachingGraphQLResolver : IConfigureExecution
options.Schema = await GetSchemaAsync(context.App);
options.HandleError(serviceProvider);
return await next(options);
var a = await next(options);
return a;
}
public async Task<GraphQLSchema> GetSchemaAsync(IAppEntity app)

35
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ErrorProvider.cs

@ -0,0 +1,35 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using GraphQL;
using GraphQL.Execution;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Validation;
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types;
public sealed class ErrorProvider : ErrorInfoProvider
{
public override ErrorInfo GetInfo(ExecutionError executionError)
{
var actual = base.GetInfo(executionError);
if (executionError.InnerException is ValidationException or DomainException)
{
if (!string.IsNullOrWhiteSpace(actual.Message))
{
actual.Message = $"{actual.Message} - {executionError.InnerException.Message}";
}
else
{
actual.Message = executionError.InnerException.Message;
}
}
return actual;
}
}

5
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ErrorVisitor.cs

@ -33,11 +33,6 @@ internal static class ErrorVisitor
log.LogError(context.OriginalException, "Failed to resolve execute query.");
}
if (context.OriginalException is ValidationException or DomainException)
{
context.Exception = new ExecutionError(context.OriginalException.Message);
}
return Task.CompletedTask;
};
}

3
backend/src/Squidex/Config/Web/WebServices.cs

@ -7,6 +7,7 @@
using GraphQL;
using GraphQL.DI;
using GraphQL.Execution;
using GraphQL.Server.Transports.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
@ -17,6 +18,7 @@ using Squidex.Config.Domain;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Entities;
using Squidex.Domain.Apps.Entities.Contents.GraphQL;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types;
using Squidex.Infrastructure.Caching;
using Squidex.Infrastructure.Json.Objects;
using Squidex.Pipeline.Plugins;
@ -107,6 +109,7 @@ public static class WebServices
services.AddGraphQL(builder =>
{
builder.UseApolloTracing();
builder.AddErrorInfoProvider<ErrorProvider>();
builder.AddSchema<DummySchema>();
builder.AddSystemTextJson();
builder.AddDataLoader();

Loading…
Cancel
Save