title: YII 2.0 REST API error handler
body: <p>How to set a REST API error handler, when API used as a module.
  I'm getting an invalid 404 found exception in HTML response rather than a json/xml response.</p>
  
  <p>this is the sample api URL with an invalid entry point</p>
  
  <p><strong><a href="http://localhost.backend.com/api/v1/invalidentrypoint" rel="noreferrer">http://localhost.backend.com/api/v1/invalidentrypoint</a></strong></p>
  
  <p>here api is in a module and v1 in nested with api module.</p>
  
  <p>the reponse is </p>
  
  <p><strong>Not Found (#404)
  Unable to resolve the request "api/v1/invalidentrypoint".
  The above error occurred while the Web server was processing your request.
  Please contact us if you think this is a server error. Thank you.</strong></p>
  
  <p>I'm expecting a response like </p>
  
  <p>**HTTP/1.1 404 Not Found
  Date: Sun, 02 Mar 2014 05:31:43 GMT
  Server: Apache/2.2.26 (Unix) DAV/2 PHP/5.4.20 mod_ssl/2.2.26 OpenSSL/0.9.8y
  Transfer-Encoding: chunked</p>
  
  <p>Content-Type: application/json; charset=UTF-8
  {
      "type": "yii\web\NotFoundHttpException",
      "name": "Not Found Exception",
      "message": "The requested resource was not found.",
      "code": 0,
      "status": 404
  }**</p>
  
  <p>please help.</p>