Improved Error Messages on Client-Side Errors #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reason for this PR
As reported in #34, the error messages returned by the webapi in cases of invalid queries / invalid query limits / errors during database interaction have all been 500 Internal Server Errors, and even exposed some application internals.
This implies that regular users may not understand the cause for a query failure, and malicious users may learn something about private data.
Changes in this PR
Introduced distinct HttpResonses on different errors:
500 Internal Server Errorwill be returned. The StatusDescription will contain a JSON object holding amsg("Database Communication Failed") and aqueryfield, the latter holding the original query that triggered the error.400 Bad Requestis returned. The StatusDescription also holds the aforementioned JSON object, with themsgstating that the limit has been exceeded, including the value of the limit.400 Bad Requestis returned. The StatusDescription also holds the aforementioned JSON object, with themsgexplaining that there was a syntax error in the query, including the line and column of the error.400 Bad Requestis returned. The StatusDescription also holds the aforementioned JSON object. Themsgstates that there were unknown field names, and an additional attributeinvalid_fieldsholds an array of all invalid field names.500 Internal Server ErrorAdditional Context
A upcoming PR for the delphi-cli will introduce support for the
400 Bad Requestresponses, which will then print the error messages in order to explain search errors to the user. EDIT: PR is at delphi-hub/delphi-cli#46Issues