Throwing Frapi Errors

Many people have asked us how do you throw an error from a Frapi action? Well it’s actually quite simple.

As you know when you generate an action in frapi, it generates executeAction(), executeGet(), etc. To throw an exception from your HTTP GET handler you would do something like such:

public function executeGet()
{
    throw new Frapi_Error('ERROR_CODE', 'The error message to display', 405);
}

As you can see, one simply has to throw a new Frapi_Error with either 2 or 3 parameters. The first parameter is the error code, the second the message to return to developers and the third, which is an optional parameter, is the HTTP Response code to return with the error.

For instance, the above request would return the following JSON payload:

{
    "errors":[{
        "message":"The error message to display",
        "name":"ERROR_CODE","at":""
    }]
}

or if XML is requested it would return the following response:

            The error message to display
            ERROR_CODE
0 Comments

Happy to release!

This is a very short post to simply say that we are more than delighted to finally announce our official pre-beta release!

0 Comments