Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Docs Request Errors

Frank Kleine edited this page Apr 7, 2012 · 1 revision

Table of Contents

Request Value Errors

When using Request Filters those filters are allowed to collect errors about the request value to filter. These request value errors are collected and can be checked later in the request stage.

Accessing collected request value errors

To check if during filtering of request values any errors occurred the net::stubbles::ipo::request::stubRequest interface provides three methods to gain access to the error collection:

$request->paramErrors(); // all collected errors for filtered request parameters
$request->headerErrors(); // all collected errors for filtered request headers
$request->cookieErrors(); // all collected errors for filtered request cookies
$request->bodyErrors(); // all collected errors for the filtered request body

Each method returns an instance of net::stubbles::ipo::request::stubRequestValueErrorCollection. All subsequent chapters refer to method calls on this instance.

Check for value errors

The collection class offers several different methods to check if there are any request value errors:

$requestValueErrorCollection->count(); Returns number of overall request value errors.

$requestValueErrorCollection->exist(); Checks whether there are any request value errors at all (returns true or false.

$requestValueErrorCollection->existFor($valueName); Checks if a request value error exists for a specific value.

$requestValueErrorCollection->existForWithId($valueName, $errorId); Checks if a specific request value error exists for a specific value.

Retrieve value errors

You can either retrieve a list of all value errors, all value errors for a specific value, or a specific error for a specific value:

$requestValueErrorCollection->get(); Returns an array containing all collected request value errors.

$requestValueErrorCollection->getFor($valueName); Returns an array containing all collected request value errors for this value.

$requestValueErrorCollection->getForWithId($valueName, $errorId); Returns a specific value error for a specific value.

Add a value error manually

To add an error value manually the instance provides the add() method:

$requestValueErrorCollection->add(stubRequestValueError $valueError, $valueName); Adds a request value error for given value name.

Creating request value errors

By default Stubbles already delivers a lot of request value errors with its release. You can check them here: [source:framework/trunk/src/main/resources/ipo/request.ini]. But of course you can create your own request value errors within your application. In order to do this create a property file in src/main/resources/ipo/request.ini. Here you can add your own definitions. The key of a section is the id of the request value error, subsequently the different error message follows for different language. You should also provide a default entry which will be used in case the application runs in a language where no error message is defined for this specific error.

You can also use your own application file to overwrite request value error messages provided by Stubbles. To do this simply add a definition with the same id in your own configuration.

Create a request value error instance

To create a request value error instance out of the configuration the factory class net::stubbles::ipo::request::stubRequestValueErrorFactory is used.

Clone this wiki locally