Skip to content

Commit

Permalink
Added more error codes. (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Aug 23, 2019
1 parent df41ca9 commit f93d010
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/Core/Abstractions/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class Execution
public const string Timeout = "EXEC_TIMEOUT";
public const string QueryNotFound = "PERSISTED_QUERY_NOT_FOUND";
public const string NonNullViolation = "EXEC_NON_NULL_VIOLATION";
public const string CachedQueryNotFound = "CACHED_QUERY_NOT_FOUND";
}

internal static class Schema
Expand All @@ -31,6 +32,28 @@ internal static class Schema
public const string ArgumentValueTypeWrong = "TS_ARG_VALUE_TYPE_WRONG";
public const string InvalidArgument = "TS_INVALID_ARG";
public const string NonNullArgument = "TS_ARG_NON_NULL";
public const string InterfaceNotImplemented = "SCHEMA_INTERFACE_NO_IMPL";
}

public static class Filtering
{
public const string FilterObjectType = "FILTER_OBJECT_TYPE";
}

public static class Sorting
{
public const string SortObjectType = "SORT_OBJECT_TYPE";
}

public static class Serialization
{
public const string ResultTypeNotSupported = "RESULT_TYPE_NOT_SUPPORTED";
}

public static class Server
{
public const string RequestInvalid = "INVALID_REQUEST";
public const string MaxRequestSize = "MAX_REQUEST_SIZE";
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Core/Execution/Middleware/ParseQueryMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Task InvokeAsync(IQueryContext context)
context.Result = QueryResult.CreateError(
_errorHandler.Handle(ErrorBuilder.New()
.SetMessage("CachedQueryNotFound")
.SetCode("CACHED_QUERY_NOT_FOUND")
.SetCode(ErrorCodes.Execution.CachedQueryNotFound)
.Build()));
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IEnumerable<ISchemaError> Validate(
CultureInfo.InvariantCulture,
"There is no object type implementing interface `{0}`.",
interfaceType.Name.Value))
.SetCode("SCHEMA_INTERFACE_NO_IMPL")
.SetCode(ErrorCodes.Schema.InterfaceNotImplemented)
.SetTypeSystemObject(interfaceType)
.AddSyntaxNode(interfaceType.SyntaxNode)
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public static Task SerializeAsync(
}
else
{
// TODO : resources
return serializer.SerializeAsync(
QueryResult.CreateError(
ErrorBuilder.New()
.SetMessage("Result type not supported.")
.SetCode("RESULT_TYPE_NOT_SUPPORTED")
.SetCode(ErrorCodes.Serialization.ResultTypeNotSupported)
.Build()),
outputStream,
cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion src/Server/AspNetCore.HttpPost/HttpPostMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ await ExecuteOperationBatchAsync(
var result = QueryResult.CreateError(
ErrorBuilder.New()
.SetMessage("Invalid GraphQL Request.")
.SetCode("INVALID_REQUEST")
.SetCode(ErrorCodes.Server.RequestInvalid)
.Build());

SetResponseHeaders(
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Server/RequestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Task<IReadOnlyList<GraphQLRequest>> ReadAsync(
throw new QueryException(
ErrorBuilder.New()
.SetMessage("Max request size reached.")
.SetCode("MAX_REQUEST_SIZE")
.SetCode(ErrorCodes.Server.MaxRequestSize)
.Build());
}
},
Expand Down

0 comments on commit f93d010

Please sign in to comment.