0

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?

David Benko
  • 373
  • 1
  • 6
  • 15

1 Answers1

3

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

Arul Kumaran
  • 983
  • 7
  • 23
  • also is there an easy way to log the exceptions for debug purposes? Lets say I want to find bad calls in my app, its much easier to log everything from the api – David Benko Nov 11 '13 at 19:50
  • 1
    You can write your own compose class using the iCompose interface and log the exceptions from there – Arul Kumaran Nov 12 '13 at 04:58