reetp / rocket-chat-rest-client

Rocket Chat REST API client in PHP
0 stars 0 forks source link

Call to undefined method #1

Open reetp opened 5 years ago

reetp commented 5 years ago

Added enhanced error handling to the code on the Dev branch.

I keep getting 'call to undefined method'

Here I added https://github.com/reetp/rocket-chat-rest-client/blob/development/src/Client.php

 protected function createExceptionFromResponse($response, $prefix){

(Have tried public/private/protected but none seem to work !)

I then have this sort of thing in \Model\Room\Channel.php https://github.com/reetp/rocket-chat-rest-client/blob/development/src/Model/Room/Channel.php

 public function postInChannel( $text ) {
blah

if($response is ok){ 
blah
}
else {
            throw $this->createExceptionFromResponse($response, "Could not postInChannel");
}

I force an error, it hits the throw line and then dies.

Uncaught Error: Call to undefined method RocketChat\Model\Room\Channel::createExceptionFromResponse() in /src/Model/Room/Channel.php:173

My guess is the namespace malarkey is screwed but I just can't see how

reetp commented 5 years ago

Because it isn't in a try/catch block I think it needs

https://www.php.net/manual/en/language.exceptions.php

When an exception is thrown, code following the statement will not be executed, and PHP will attempt to find the first matching catch block. If an exception is not caught, a PHP Fatal Error will be issued with an "Uncaught Exception ..." message, unless a handler has been defined with set_exception_handler().

https://www.tutorialspoint.com/php/php_error_handling.htm

OK, so either rewrite try/catch & stuff or forget it.