From 33c2e6e1a48334cc06fbf697f4719d45e4f476c5 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 30 Jun 2025 11:54:44 +0100 Subject: [PATCH] Better handle graphql commit errors (#343) * Better handle graphql commit errors * add graphql error test --- src/Speckle.Sdk/Api/Exceptions.cs | 11 +++++++++++ src/Speckle.Sdk/Api/GraphQL/GraphQLErrorHandler.cs | 1 + .../Speckle.Sdk.Tests.Unit/Api/GraphQLErrorHandler.cs | 1 + 3 files changed, 13 insertions(+) diff --git a/src/Speckle.Sdk/Api/Exceptions.cs b/src/Speckle.Sdk/Api/Exceptions.cs index b7267df9..94833754 100644 --- a/src/Speckle.Sdk/Api/Exceptions.cs +++ b/src/Speckle.Sdk/Api/Exceptions.cs @@ -126,3 +126,14 @@ public sealed class WorkspacePermissionException : SpeckleGraphQLException public WorkspacePermissionException(string? message, Exception? innerException) : base(message, innerException) { } } + +public sealed class CannotCreateCommitException : SpeckleGraphQLException +{ + public CannotCreateCommitException() { } + + public CannotCreateCommitException(string? message) + : base(message) { } + + public CannotCreateCommitException(string? message, Exception? innerException) + : base(message, innerException) { } +} diff --git a/src/Speckle.Sdk/Api/GraphQL/GraphQLErrorHandler.cs b/src/Speckle.Sdk/Api/GraphQL/GraphQLErrorHandler.cs index 4fa7d9f5..14e902e6 100644 --- a/src/Speckle.Sdk/Api/GraphQL/GraphQLErrorHandler.cs +++ b/src/Speckle.Sdk/Api/GraphQL/GraphQLErrorHandler.cs @@ -33,6 +33,7 @@ internal static class GraphQLErrorHandler "BAD_USER_INPUT" => new SpeckleGraphQLBadInputException(message), "INTERNAL_SERVER_ERROR" => new SpeckleGraphQLInternalErrorException(message), "WORKSPACES_MODULE_DISABLED_ERROR" => new SpeckleGraphQLWorkspaceNotEnabledException(message), + "COMMIT_CREATE_ERROR" => new CannotCreateCommitException(message), _ => new SpeckleGraphQLException(message), }; exceptions.Add(ex); diff --git a/tests/Speckle.Sdk.Tests.Unit/Api/GraphQLErrorHandler.cs b/tests/Speckle.Sdk.Tests.Unit/Api/GraphQLErrorHandler.cs index f3adbcb8..2aa0b3bc 100644 --- a/tests/Speckle.Sdk.Tests.Unit/Api/GraphQLErrorHandler.cs +++ b/tests/Speckle.Sdk.Tests.Unit/Api/GraphQLErrorHandler.cs @@ -23,6 +23,7 @@ public class GraphQLErrorHandlerTests ]; yield return [typeof(SpeckleGraphQLException), new Map { { "foo", "bar" } }]; yield return [typeof(SpeckleGraphQLException), new Map { { "code", "CUSTOM_THING" } }]; + yield return [typeof(CannotCreateCommitException), new Map { { "code", "COMMIT_CREATE_ERROR" } }]; } [Theory]