# Errors
Exception
and Throwable
exceptions thrown during processing such as SQL driver errors, operation errors etc. will
be converted into
OData errors (opens new window).
OData errors have a suitable HTTP response code and a standard JSON object format to present information about the error.
An example OData error object:
{
"error": {
"code": "no_handler",
"message": "No route handler was able to process this request",
"target": null,
"details": [],
"innererror": {}
}
}
2
3
4
5
6
7
8
9
# Streaming responses
Lodata implements Streaming JSON by default. This is very efficient, but it can encounter a situation where a fatal error occurs part way through sending a response, and after sending a successful HTTP code to the client.
When this happens Lodata will leave the response as incomplete JSON, but will append
the header OData-Error
as a trailing header (opens new window)
if supported by the transport protocol (eg HTTP/1.1 with chunked transfer encoding, or HTTP/2).
Calling clients can disable the streaming behaviour by setting the Accept
header with a parameter that includes
streaming=false
.
For example: Accept: application/json;streaming=false
. This will buffer the response server-side,
and return only error information and correct status codes.
Alternatively, you can globally disable the streaming behaviour by setting streaming
to false
in the lodata.php
config file. Clients that want the streaming behaviour in this case can still
set the Accept
header with a parameter of streaming=true
.
Any calling client in streaming mode must be aware of this in order to deal with JSON responses that cannot be decoded, and in this event should check the trailing header to get the JSON error object.
# Exceptions
To retrieve the original exception that caused the Lodata error, the getOriginalException()
method can be used.
try {
// XXX
} catch (ProtocolException $protocolException) {
/** @var Throwable $originalException */
$originalException = $protocolException->getOriginalException();
}
2
3
4
5
6
Or, if you have captured a Response
object the exception can be obtained with:
$originalException = $response->exception->getOriginalException();