IOrbErrorHandler Interface
The IOrbErrorHandler interface specifies the httpError method, which has the following signature.
httpError(statusCode: Integer;
phrase: String;
httpMeth: String;
httpUrl: String;
httpBody: Binary;
except: Exception): Binary;
If Orb encounters an error while servicing a web request and an error handler object has been provided with the errorHandler method, the httpError method on the object is invoked.
The following table lists the parameters of the httpError method.
| Parameter | Description |
|---|---|
| statusCode |
The HTTP status code that represents the error; for example, if the error is that the requested route is not found, the status code is 404. If the error is that an internal exception occurred, this parameter is 500, and so on. |
| phrase |
The reason phrase associated with the HTTP status code; for example, if the statusCode parameter value is 404, the value of this parameter is "Not Found". This parameter is provided for convenience so that the description of the error can be sent in the response, if required. |
| httpMeth | The string representation of the HTTP request method; for example, "GET" or "POST". |
| httpUrl |
The URL of the requested route, including the query string, if any; for example, the query string could be "/account?id=42". To aid debugging, the value of this parameter is the complete path sent by the browser; that is, it includes any prefix removed by the strip method. If the error is a 404 error resulting from a request to a virtual directory path, the value of this parameter is the physical path of the file that was requested. |
| httpBody |
The POST body contained in the HTTP request represented in query string format. The value of this parameter is null if the request did not send POST data. This parameter is provided for convenience; for example, for logging or debugging. |
| except |
If the error is the result of an exception, the value of this parameter is the instance of the exception that occurred. If the error is not the result of an exception, the value of this parameter is null. |
The Binary value the method returns is sent to the browser; for example, this could be the result of a bind method call.
If the exception raised is the result of a TCP/IP connection error, this method is called but the response is not sent to the browser.
The following method shows an example of using the bind method to return different templates based on the error.
httpError(statusCode: Integer;
phrase: String;
httpMeth: String;
httpUrl: String;
httpBody: Binary;
except: Exception): Binary;begin
// this could be a method that saves info about the request
logError(statusCode, httpMeth, httpUrl, httpBody, except);
// display a custom error page for common error codes
if statusCode = 404 then
return Orb@bind("error404", null);
elseif statusCode = 403 then
return Orb@bind("error403", null);
elseif statusCode = 500 then
return Orb@bind("error500", null);
endif;
// display a generic error page for any other errors
return Orb@bind("genericError", null);
end;
Take care exposing exception details in your error response. Exceptions are internal to your application and can contain potentially sensitive information. The error information you return should be helpful information for the user.
