-
Notifications
You must be signed in to change notification settings - Fork 246
Correcting behaviour of BadRequests returning InternalServerError #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correcting behaviour of BadRequests returning InternalServerError #783
Conversation
…t' of https://github.com/Azure/hawaii-gql into dev/agarwalayush/insertOperationConflictWithFKConstraint
…t' of https://github.com/Azure/hawaii-gql into dev/agarwalayush/insertOperationConflictWithFKConstraint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions..
src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs
Outdated
Show resolved
Hide resolved
…t' of https://github.com/Azure/hawaii-gql into dev/agarwalayush/insertOperationConflictWithFKConstraint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some last nit comments to resolve and then looks good!
src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs
Outdated
Show resolved
Hide resolved
/// <returns>true/false</returns> | ||
public virtual bool IsBadRequestException(DbException e) | ||
{ | ||
return e.SqlState is not null && badRequestErrorCodes.Contains(e.SqlState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mentioned this in another comment, but I think that comment might have been buried from updates. If MsSql
is the only case here e.SqlState
can be null
, and MsSql
never calls into this function, do we still need the null check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think SQLSTATE will be null in mysql,pgsql but as a defensive approach I am putting this null check because the string SQLSTATE is nullable in declaration.
Why make this change?
Previously, for exceptions that were arising because of users sending bad request to the database rather than an Internal Server failure of the database, we were still throwing exception with status code
500
(InternalServerError
) rather than (400
)BadRequest
. This PR changes that behaviour to thrown exception with status code400
.Useful Links
What is this change?
We will now have 3 seperate subclasses of
DbExceptionParser
. The 3 subclasses for MySql, MsSql, PostgreSql will have their own implementation of the methodIsBadRequestException()
, which depending on the database's way of classifying exceptional conditions viaSqlState
(MySql/PgSql) orNumber
(MsSql), will return a boolean value indicating whether the exception is to be considered to have occurred because of a bad request.Also the severity of Stylecop rule
CA1051
was reduced tosuggestion
to declare a protected field inDbExceptionParser
class.How was this tested?