refactored errors in the api layer to be of type ApiError

Signed-off-by: Damien Le Berrigaud <damien@pivotallabs.com>