Skip to content

返回值和可能抛的Exception应该有更清晰的注释说明 #19

@icedfish

Description

@icedfish
class Charge extends ApiResource
{
    /**
     * @param string $id The ID of the charge to retrieve.
     * @param array|string|null $options
     *
     * @return Charge
     */
    public static function retrieve($id, $options = null)
    {
        return self::_retrieve($id, $options);
    }

Charge类的多个方法实际上都是会抛Exception的,比如上述retrieve()方法在$id非法时就会抛InvalidRequestError。

希望官方在SDK各个常用方法上标准清楚可能返回的Exception类型,开发的时候IDE会对没有捕捉的Excetion进行提示,调用者能更清楚的知道如何应对返回。

     /** eg:
     * @throws InvalidRequestError if the error is caused by the user.
     * @throws AuthenticationError if the error is caused by a lack of
     *    permissions.
     * @throws ApiError otherwise.
     */

其实retrieve()何时会返回string或者null我到现在都没明白,所以校验返回的时候很痛苦,只检查是否抛Exception不知是否够用。 希望增加类似的说明。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions