You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that the error responses needs to be more structured.
Right now an error response looks something like this when creating a user:
{"message":"Invalid password: Password must be between 6 and 32 chars and contain ...","code":400, ...
I will have to parse response message to figure out the error. If the message is translated it makes it even more difficult.
would like something like this
{
"errors":{
[
"type": "parameter",
"name": "password",
"message": "Invalid password: Password must be between 6 and 32 chars and contain..."
]
...
}
such an error is very easy to handle and put into the UI.
@wentzlau yeh, this is definitely an area where we can do better, I would really appreciate if you try and take a look at the way we handle error messages today and help me think how we can manage this better without creating a huge overhead.
Please keep in mind that there are some cases where we are intentionally giving general errors in favor of security.
I think that you should handle validation errors differently from exceptions. Right now you handle validation errors as exceptions and you are only able to catch one validation error per post to the api. All validation errors should be found in a request and in case of error raise a validation exception that holds all errors.
A rule of thumb is that if a user can move forward by changing the input it is a validation error. The validation error message should explain to the user what should be fixed. If the system fails in a way that prevent the user from moving forward in the UI flow it is an exception often such errors/exceptions requires technical support.
If you raise a validation exception it could be caught in the api frameworks for appwrite.
in python a call to appwrite could look like this
user=User(client)
try:
user.create_user(email, password, name)
exceptValidationExceptionex:
forvalidation_errorinex.validation_errors:
#prepare response to UI with validation errors exceptExceptionex:
#Something went wrong log the error and prepare recovery in UI log.exception(ex)
Using error stacks instead of throwing an exception might be a good option as long as it doesn't effect the server in any other way. It might be a really big change so I'll have to do a farther research in that area and I guess that for now this is not a top priority.
Even if we'll change the validation method this still won't solve the problem where some errors we throw might be better described. I guess the most effective way to improve this will be to manually review each error.
Another idea I had is to allow error localisation and that way we will allow developers to just show users the errors directly from the API response.
A solution would be to include an error code in the current error response. You could prepend the error code with error type like "Fatal.SMTPServiceNotFound", "Validation.InvalidPassword" or "Authentication.UnknownUserOrPassword"
something like:
{ "error": "Validation.InvalidPassword", "message":"Invalid password: Password must be between 6 and 32 chars and contain ...","code":400, ...
Activity
eldadfux commentedon Nov 22, 2019
@wentzlau yeh, this is definitely an area where we can do better, I would really appreciate if you try and take a look at the way we handle error messages today and help me think how we can manage this better without creating a huge overhead.
Please keep in mind that there are some cases where we are intentionally giving general errors in favor of security.
This is our current error handler:
https://github.com/appwrite/appwrite/blob/master/app/app.php#L267
And all user input validation is handled directly at the framework level:
https://github.com/utopia-php/framework/blob/master/src/App.php#L440
(Utopia framework is maintained by the Appwrite team)
This is an example controller:
https://github.com/appwrite/appwrite/blob/master/app/controllers/storage.php#L116
wentzlau commentedon Nov 22, 2019
I think that you should handle validation errors differently from exceptions. Right now you handle validation errors as exceptions and you are only able to catch one validation error per post to the api. All validation errors should be found in a request and in case of error raise a validation exception that holds all errors.
A rule of thumb is that if a user can move forward by changing the input it is a validation error. The validation error message should explain to the user what should be fixed. If the system fails in a way that prevent the user from moving forward in the UI flow it is an exception often such errors/exceptions requires technical support.
If you raise a validation exception it could be caught in the api frameworks for appwrite.
in python a call to appwrite could look like this
eldadfux commentedon Nov 22, 2019
Using error stacks instead of throwing an exception might be a good option as long as it doesn't effect the server in any other way. It might be a really big change so I'll have to do a farther research in that area and I guess that for now this is not a top priority.
The current implementation allows a developer to distinguish input error from other errors by using the HTTP status code. Appwrite returns 400 status codes for every bad input (or "bad request").
More about Appwrite errors can be found here: https://appwrite.io/docs/error-codes
Even if we'll change the validation method this still won't solve the problem where some errors we throw might be better described. I guess the most effective way to improve this will be to manually review each error.
Another idea I had is to allow error localisation and that way we will allow developers to just show users the errors directly from the API response.
wentzlau commentedon Nov 24, 2019
A solution would be to include an error code in the current error response. You could prepend the error code with error type like "Fatal.SMTPServiceNotFound", "Validation.InvalidPassword" or "Authentication.UnknownUserOrPassword"
something like:
{ "error": "Validation.InvalidPassword", "message":"Invalid password: Password must be between 6 and 32 chars and contain ...","code":400, ...
In the appwrite code
$validator->getErrorCode() returns "Validation.InvalidPassword"
TorstenDittmann commentedon Apr 6, 2021
As we are implementing https://github.com/appwrite/rfc/blob/main/013-custom-exception-on-all-sdks.md right now, this issue is soon to be resolved.
eldadfux commentedon Apr 10, 2021
We have already released this feature on some SDKs (Node, Dart), should be available on all SDKs alongside the release of Appwrite 0.8
Merge pull request appwrite#260 from utopia-php/fix/queue-redis-auth