禁用PHP 401错误警告

时间:2014-05-14 14:22:59

标签: php

我在使用api调用的应用程序上工作。当我输入正确的api键时,一切正常,如果我把错误的细节我会得到401 error。我知道这个错误意味着什么我期待它所以我有我自己的处理程序,问题是浏览器输出的警告。我试图禁用每个错误,但后来我无法调试应用程序,是否可以从php的配置中禁用它?如果有,怎么样? 感谢

代码:

$apicalldata = file_get_contents("https://api.digitalocean.com/v1/droplets/?client_id=xxx&api_key=xxx");

$call = json_decode($apicalldata);


$status = $call->status;
if ($status != "OK") {
echo "Sorry, the API details are wrong!";
}

2 个答案:

答案 0 :(得分:1)

只需输入@file_get_contents这将隐藏错误!

答案 1 :(得分:0)

我建议使用Try Catch语法

PHP Try Catch Docs

try{
   $apicalldata = file_get_contents("https://api.digitalocean.com/v1/droplets/?client_id=xxx&api_key=xxx");

} catch (exception $e) {
 /*** bad return (401)***/
   echo "Sorry, the API details are wrong!";
}  
  /*** good return ***/
  doSomething()