Skip to content

Commit eab3471

Browse files
committed
Removed MsSql specific error code checking, with the tradeoff of not sending HTTP 400 for trying to insert in a table with autogen'd primary key. Adjusted test framework to accommodate.
1 parent 97df382 commit eab3471

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

DataGateway.Service.Tests/SqlTests/RestApiTestBase.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,8 @@ await SetupAndRunRestApiTest(
472472
operationType: Operation.Upsert,
473473
requestBody: requestBody,
474474
exception: true,
475-
expectedErrorMessage: $"Could not perform the given mutation on entity books. " +
476-
"Request contains value for field that is autogenerated.",
477-
expectedStatusCode: (int)HttpStatusCode.BadRequest,
475+
expectedErrorMessage: $"Could not perform the given mutation on entity books.",
476+
expectedStatusCode: (int)HttpStatusCode.InternalServerError,
478477
expectedSubStatusCode: DatagatewayException.SubStatusCodes.DatabaseOperationFailed.ToString()
479478
);
480479
}

DataGateway.Service/Resolvers/SqlMutationEngine.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,9 @@ await PerformMutationOperation(
151151
Console.Error.WriteLine(ex.Message);
152152
Console.Error.WriteLine(ex.StackTrace);
153153

154-
StringBuilder messageDetails = new($"Could not perform the given mutation on entity {context.EntityName}.");
155-
int statusCode = (int)HttpStatusCode.InternalServerError;
156-
SqlException sqlException = ex as SqlException;
157-
158-
if (sqlException != null)
159-
{
160-
if (sqlException.Number == 544)
161-
{
162-
messageDetails.Append(" Request contains value for field that is autogenerated.");
163-
statusCode = (int)HttpStatusCode.BadRequest;
164-
}
165-
}
166-
167154
throw new DatagatewayException(
168-
message: messageDetails.ToString(),
169-
statusCode: statusCode,
155+
message: $"Could not perform the given mutation on entity {context.EntityName}.",
156+
statusCode: (int)HttpStatusCode.InternalServerError,
170157
subStatusCode: DatagatewayException.SubStatusCodes.DatabaseOperationFailed);
171158
}
172159
catch (Exception ex)

0 commit comments

Comments
 (0)