Skip to content

请问删除资源中的文件,返回的$err的数据类型是什么 #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cgfeel opened this issue Mar 23, 2021 · 1 comment
Closed

Comments

@cgfeel
Copy link

cgfeel commented Mar 23, 2021

代码如下

        $auth = new QiniuAuth(
            env('QINIU_ACCESS'), env('QINIU_SECRET')
        );

        $config = new QiniuConfig();
        $bucketManager = new BucketManager($auth, $config);

        $bucket = env('ATTACH_BUCKET');
        $err = $bucketManager->delete($bucket, $key);

        dd($err);

测试了两遍,分别如下

删除成功返回

array:2 [
  0 => null
  1 => null
]

删除失败返回

array:2 [
  0 => null
  1 => Qiniu\Http\Error^ {}
]
  1. 第一个参数是什么意思,成功和失败都返回null
  2. 第二个参数从字面上看是不是一个异常Exception,文档里好像没有关于Qiniu\Http\Erro说明
@lihsai0
Copy link
Collaborator

lihsai0 commented Dec 21, 2021

@aiyuchen

第一个参数是什么意思,成功和失败都返回null

第一个参数是服务端响应的 body 信息,成功时,如果服务端没有响应任何信息则为 null,如果返回了信息则为 json 数据。

list($ret, $err) = $bucketManager->delete($bucket, $key); 为例,如要判断删除成功,判断 $err != null 即可。

第二个参数从字面上看是不是一个异常Exception,文档里好像没有关于Qiniu\Http\Erro说明

否,为自定义 Error 类。以 list($ret, $err) = $bucketManager->delete($bucket, $key); 为例,该 $err 实例上有如下几个方法可调用:

  • $err -> code() 返回 HTTP Code;
  • $err -> message() 返回错误信息;
  • $err -> getResponse() 返回 Qiniu\Http\Response 的实例;

如果还有其他疑问欢迎随时重新打开这个 issue!

@lihsai0 lihsai0 closed this as completed Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants