dqo88037
2016-01-08 07:16
浏览 109
已采纳

如何在PHP中的OpenFire Restapi中处理异常?

Currently I installed openfire in my server and started to use it. I tried to create a user in openfire using Restapi . And I got output as I expected.

Now i tried to create a user with the username "abcdef" which is already existed. I want a message that says "username already exists" but instead I get an exception.

The exception:

Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] http://myip:9090/plugins/restapi/v1/users [status code] 409 [reason phrase] Conflict' in /var/www/html/open_fire_internal/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:88

The message from the exception:

Client error response [url] http://myip:9090/plugins/restapi/v1/users [status code] 409 [reason phrase] Conflict

Stack trace:

#0 [...]/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response))
#1 [...]/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(109): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete')
#2 [...]/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent))
#3 [...]/vendor/guzzlehttp/guzzle/src/RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))in /var/www/html/open_fire_internal/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 88

So can anyone help me to overcome from this issue?

图片转代码服务由CSDN问答提供 功能建议

目前我在服务器中安装了openfire并开始使用它。 我尝试使用Restapi在openfire中创建用户。 我按预期输出了输出。

现在我尝试创建一个用户名为“abcdef”的用户,该用户已经存在。 我想要一条消息,上面写着“用户名已存在”,但我得到了一个异常。

异常:

  Uncaught exception'GuzzleHttp  \ Exception \ ClientException'带消息'客户端错误响应[url] http:// myip:9090 / plugins / restapi / v1 / users [状态代码] 409 [原因短语]冲突'/ var / www / html / open_fire_internal /  vendor / guzzlehttp / guzzle / src / Exception / RequestException.php:88 
   
 
 

来自异常的消息:

\ n

客户端错误响应[url] http:// myip:9090 / plugins / restapi / v1 / users [status code] 409 [reason phrase] Conflict

堆栈跟踪:

   #0 [...] / vendor / guzzlehttp / guzzle / src / Subscriber / HttpError.php(33):GuzzleHttp \ Exception \ RequestException :: create(Object(GuzzleHttp \ Message \ Request),Object(GuzzleHttp \ Message \ Response)  ))
#1 [...] / vendor / guzzlehttp / guzzle / src / Event / Emitter.php(109):GuzzleHttp \ Subscri  ber \ HttpError-> onComplete(Object(GuzzleHttp \ Event \ CompleteEvent),'complete')
#2 [...] / vendor / guzzlehttp / guzzle / src / RequestFsm.php(91):GuzzleHttp \ Event \ 发射器 - >发射('完整',对象(GuzzleHttp \ Event \ CompleteEvent))
#3 [...] / vendor / guzzlehttp / guzzle / src / RequestFsm.php(132):GuzzleHttp \ RequestFsm->  __invoke(Object(GuzzleHttp \ Transaction))位于第88行的/var/www/html/open_fire_internal/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php 
   
 
 < 那么,任何人都可以帮助我克服这个问题吗? 
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutizong8099 2016-01-08 10:05
    已采纳

    First check whether the user is exists or not than add them

    $user = $api->getuser($username);
    
    if(!$user)
    {
    $result = $api->addUser('Username', 'Password', 'Real Name', 'email@email.tld', array('Group 1'));
    
    // Check result if command is succesful
    if($result) {
        // Display result, and check if it's an error or correct response
        echo ($result['result']) ? 'Success: ' : 'Error: ';
        echo $result['message'];
    } else {
        // Something went wrong, probably connection issues
    }
    }
    else
    {
    
    echo 'user already exists';
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题