🚀 Feature: Constants for Error Types

未关闭
#698 17 条评论 1 个 reaction 已指派 2 人 在 GitHub 查看

维护者通常 1 天内回复

@stnguyen90 已经在做这个了。

开始于 2023年10月9日。

  • #716 来自 @lohanidamodar —— 已合并
  • #724 来自 @35C4n0r —— 已关闭,未合并

评估

这个 Issue 还没有评估数据。

描述

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?
主要语言
Twig
星标
330
派生
212
平均合并
12 小时 3 分钟
30 天内合并 PR
131

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

appwrite/sdk-generator 的其他 Issue

查看 appwrite/sdk-generator 的全部 Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。