Question

Lets say insted of just output:

{
  "error": 
  {
    "code": 500,
    "message": "Some internal error"
  }
}

I would like to output:

{
  "error": 
  {
    "code": 500,
    "message": "Some internal error",
    "error_code" : 1050
  }
}

Also is there a way we can catch all the exceptions for log purposes for example?

Was it helpful?

Solution

Use RestException to throw the exception and use the details parameter (an array) to add additional details

throw new RestException(400, 'invalid user', array('error_code' => 12002));

gives me the following

{
  "error": {
    "code": 400,
    "message": "Bad Request: invalid user",
    "error_code": 12002
  },
  "debug": {
    "source": "Say.php:5 at call stage",
    "stages": {
      "success": [
        "get",
        "route",
        "negotiate",
        "validate"
      ],
      "failure": [
        "call",
        "message"
      ]
    }
  }
}

Info:- additional debug information is returned when restler is running in debug mode. It can be turned off by using Compose::$includeDebugInfo=false;

Note:- Make sure you are using Restler 3.0 RC4 or higher

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top