문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top