🚀 Feature: Constants for Error Types

Đang mở
#698 17 bình luận 1 reaction 2 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@stnguyen90 đang làm issue này rồi.

Từ ngày 9/10/2023.

  • #716 của @lohanidamodar — đã merge
  • #724 của @35C4n0r — đã đóng, không merge

Đánh giá

Issue này chưa được đánh giá.

Mô tả

hacktoberfest
🔖 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?
Ngôn ngữ chính
Twig
Star
330
Fork
212
Merge trung bình
12 giờ 3 phút
Pull request đã merge (30 ngày)
131

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của appwrite/sdk-generator

Tất cả issue của appwrite/sdk-generator

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.