I understand how to re-throw exception, Handling them on internal MVC requests, but how to handle that - which was caught as instance of HTTP Response
from another server? Ok, I guess when ($response->status() < 300)
, But how to throw this response as exception with same body and same code?
Asked
Active
Viewed 67 times
0

LINKeRxUA
- 559
- 6
- 26
-
Are you trying to show your user response of remote server? so if remote server throw 500 error you want to throw 500 error as well? – Faraz May 11 '16 at 14:06
-
I receive response body as rendered error view and response code, Bu I want to get also message what was sent to that body – LINKeRxUA May 11 '16 at 15:56
-
no, not a remote, HMVC inside current server – LINKeRxUA May 11 '16 at 15:57
-
I don't think in HMVC (Internal request) you can get actual message without modifying you controller or Exception handler that render the actual exception. You can add condition in you master controller to check if its a internal request or not and render only message without any extra HTML or css – Faraz May 11 '16 at 16:13
-
did you managed find a solution? – Faraz May 25 '16 at 13:06
-
I think solution is to `class A` extend `Request` Class and redeclare `execute()` method. as far as I remember it works with `try{}catch(Exception $e){}`; and in new class `A` on execute do throwing of $e! – LINKeRxUA May 25 '16 at 18:30
1 Answers
0
You need to check in your master controller if its initial request or not. Using this you render full response or minimum response. Than you can use response body as error message.
class Controller_APP extends Controller {
public function after() {
if(! $this->request->is_initial ()) {
$this->response->body ( 'only message');
}else{
$this->response->body ( 'Full rendered templage');
}
}
}
You can also modify your exception handler to render only message if request is not initial request.

Faraz
- 751
- 7
- 23
-
I read some from php.net, maybe the most universal and clear way is to define `serialize`/`unserialize` and `__sleep()`/`__wakeup()` methods in Exception class, pass some custom header, such as `SerializeOnException: 1`, and handle it. if header passed and value == true, use json encoded serialized exception object as response instead of default `$error_view` – LINKeRxUA Jun 29 '16 at 09:11