Skip to content

🚀 Feature: Constants for Error Types #698

Open

Description

@stnguyen90

🔖 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:

  1. this is an example for Swagger 2. The equivalent will need to be done for OpenAPI 3
  2. we're still finalizing whether was want the types in definitions.appwriteException or definitions.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

Tasks

👀 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?

Activity

  1. sahilsaha7773 commented on Aug 10, 2023

    @sahilsaha7773

    Hey @stnguyen90, I and @goswamianshuman are working on this, could you please assign it to us?

  2. goswamianshuman commented on Aug 10, 2023

    @goswamianshuman

    Hey @stnguyen90, we are here now you can assign this PR to us.😄

  3. added
    hacktoberfest
    on Sep 30, 2023
  4. 35C4n0r commented on Oct 3, 2023

    @35C4n0r

    @Haimantika I would like to work on this Issue.

  5. Haimantika commented on Oct 3, 2023

    @Haimantika

    @Haimantika I would like to work on this Issue.

    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!

  6. monhelnog commented on Oct 3, 2023

    @monhelnog

    I would like to work on this issue

  7. Haimantika commented on Oct 3, 2023

    @Haimantika

    I would like to work on this issue

    Hi, we are assigning issues on a first-come, first-serve basis, if @35C4n0r decides to drop off, we will assign it to you.

  8. heyhimansh commented on Oct 4, 2023

    @heyhimansh

    Hey @Haimantika, i would like to work on this issue.

  9. Haimantika commented on Oct 4, 2023

    @Haimantika

    Hey @Haimantika, i would like to work on this issue.

    Hi, we are assigning issues on a first-come, first-serve basis, if @35C4n0r decides to drop off, we will assign it to you.

  10. Haimantika commented on Oct 6, 2023

    @Haimantika

    Hi @35C4n0r is there an update? The issue will be assigned to the next person in line soon due to inactivity

  11. 35C4n0r commented on Oct 6, 2023

    @35C4n0r

    Hi @Haimantika working on this, i've managed to understand the codebase, am still working on this issue.

  12. 35C4n0r commented on Oct 7, 2023

    @35C4n0r

    @stnguyen90 @Haimantika
    the URL for the Swagger API Spec is invalid

    $spec = new Swagger2(file_get_contents('https://appwrite.io/v1/open-api-2.json?extension=1'));

    Can you please inform me about the correct URL.
    For now i'm using \tests\resources\spec.json

  13. 35C4n0r commented on Oct 7, 2023

    @35C4n0r

    @stnguyen90 should we put the enum in exceptions.*.twig or create a new file for it.
    Also for the spec you provided this is the only part we should make an enum out of right?

    "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."
                        }
                    ]
                }
            }
    
  14. self-assigned this
    on Oct 9, 2023
  15. stnguyen90 commented on Oct 9, 2023

    @stnguyen90
    ContributorAuthor

    @35C4n0r,

    the URL for the Swagger API Spec is invalid

    The specs are here.

    should we put the enum in exceptions.*.twig or create a new file for it.

    In the exception file is fine.

    Also for the spec you provided this is the only part we should make an enum out of right?

    FYI, we already have appwrite/appwrite#5979 open for the specs part, although we haven't finalized where in the specs the types should go.

  16. ItzNotABug commented on Mar 1, 2024

    @ItzNotABug
    Contributor

    Commenting to get notified of any updates to this!

  17. ChiragAgg5k commented on Aug 21, 2026

    @ChiragAgg5k
    Member

    Before this can be implemented in the generator, we need an authoritative error catalog and a defined representation in the API specification.

    Could a maintainer confirm:

    Once that contract is established upstream, the per-language generation work can be scoped here.

  18. archduke1337 commented on Oct 9, 2026

    @archduke1337

    @Haimantika I would like to work on this Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

hacktoberfest

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions