Open
Description
🔖 Feature description
For the error types exposed here we should have a class with constants or an enum so we don't have to manually put the string in the code.
🎤 Pitch
Let say I want to display some error message specifically to the user depending on the type, so instead of doing this:
AppWriteException exception;
if (exception.type == 'user_already_exists') {
...
}
I could use the constant instead
AppWriteException exception;
if (exception.type == ErrorType.userAlreadyExists) {
...
}
Requirements
To implement this, we'll need to update the API specs to include the error types. For the API specs, we'll want to add an AppwriteException
schema/definition like so:
"definitions": {
"appwriteException": {
"properties": {
"message": {
"type": "string",
"description": "Error message.",
"x-example": "Invalid id: Parameter must be a valid number"
},
"type": {
"type": "string",
"description": "Error type.",
"enum": [
"general_mock",
"general_argument_invalid"
],
"x-example": "argument_invalid"
},
"code": {
"type": "integer",
"description": "Error code.",
"x-example": 400,
"format": "int32"
}
},
"x-appwrite": {
"types": [
{
"code": 400,
"type": "general_mock",
"description": "General errors thrown by the mock controller used for testing."
},
{
"code": 400,
"type": "general_argument_invalid",
"description": "The request contains one or more invalid arguments. Please refer to the endpoint documentation."
}
]
}
},
"any": {
"description": "Any",
"type": "object",
"additionalProperties": true
},
Note:
- this is an example for Swagger 2. The equivalent will need to be done for OpenAPI 3
- we're still finalizing whether was want the types in
definitions.appwriteException
ordefinitions.appwriteException.properties.types
The SDK Generator should use the API specs to generate the enums with descriptions like:
enum ErrorType {
/**
* General errors thrown by the mock controller used for testing.
*/
GeneralMock = "general_mock",
/**
* The request contains one or more invalid arguments. Please refer to the endpoint documentation.
*/
GeneralArgumentInvalid = "general_argument_invalid"
}
enum ErrorType implements Comparable<ErrorType> {
/// General errors thrown by the mock controller used for testing.
generalMock(code: 400, type: 'general_mock'),
/// General errors thrown by the mock controller used for testing.
generalArgumentInvalid(code: 400, type: 'general_argument_invalid');
const ErrorType({
required this.code,
required this.type,
});
final int code;
final String type;
@override
int compareTo(ErrorType other) => type.compareTo(other.type);
}
So that the developer's IDE will show the description like:

Tasks
- androidcli - not neededdartdenodotnetgo - not readygraphql/docs - not neededkotlinnodephppythonrest/docs - not neededrubyswiftweb
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity
sahilsaha7773 commentedon Aug 10, 2023
Hey @stnguyen90, I and @goswamianshuman are working on this, could you please assign it to us?
goswamianshuman commentedon Aug 10, 2023
Hey @stnguyen90, we are here now you can assign this PR to us.😄
35C4n0r commentedon Oct 3, 2023
@Haimantika I would like to work on this Issue.
Haimantika commentedon Oct 3, 2023
Hi @35C4n0r have assigned the issue to you! Thank you for showing interest in contributing to Appwrite! Happy Hacktoberfest 🎃
Notes:
Please update us with your progress every 3 days, so that we know that you are working on it.
Join us on Discord - https://appwrite.io/discord to chat about Hacktoberfest and Appwrite!
monhelnog commentedon Oct 3, 2023
I would like to work on this issue
Haimantika commentedon Oct 3, 2023
Hi, we are assigning issues on a first-come, first-serve basis, if @35C4n0r decides to drop off, we will assign it to you.
heyhimansh commentedon Oct 4, 2023
Hey @Haimantika, i would like to work on this issue.
9 remaining items