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:
![image](https://private-user-images.githubusercontent.com/1477010/259509826-8ffb1c3e-4490-4006-af1b-1dd87781a77a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNDQzMzksIm5iZiI6MTczOTM0NDAzOSwicGF0aCI6Ii8xNDc3MDEwLzI1OTUwOTgyNi04ZmZiMWMzZS00NDkwLTQwMDYtYWYxYi0xZGQ4Nzc4MWE3N2EucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTJUMDcwNzE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZTM1N2Q5ZTQ4OGUyNDM5YTU2NzAxNzQ2MWVhMzg0MjFjMmM1NGQ2MGUzNTJkY2JjNzEwN2NiYTAyYWE1NmM3YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.2W5Kf2K4u79F4G7162F019nj10SoBqEwj78G4GU13xA)
Tasks
- Feat: Add appwriteException with constants for error types in specs appwrite#5979
- android
- cli - not needed
- dart
- deno
- dotnet
- 🚀 Feature: Constants for error Types sdk-for-flutter#149
- go - not ready
- graphql/docs - not needed
- kotlin
- node
- php
- python
- rest/docs - not needed
- ruby
- swift
- web
👀 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