[fpc-devel] fcl-web webdata ExtJS "total" field question

Michael Van Canneyt michael at freepascal.org
Sat Aug 21 01:37:55 CEST 2010



On Fri, 20 Aug 2010, ABorka wrote:

> ...snip...
>> 
>> Exceptions are usually caught and transformed to the correct response.
>> I coded an event that allows to influence this process.
>> 
>> Michael.
>
> Yes, the ones raised within FCL-web are caught. I was thinking about the ones 
> raised within the developer's code, when handling the actions, or checking 
> the user input from form submit, etc.
> For example if I have a login form and ExtJS submits it to the server, but 
> the login or password didn't match, we need to reply with a success=false and 
> an error message in a proper response format.

I have the same kind of thing. I just do a

   Raise Exception.Create('Username and password do not match');

fcl-web catches it and returns a proper error response to the browser.

> I was thinking there could be something available for the developers to help 
> format this response properly to ExJS.

There is no need. Just raise the exception. FCl-web takes care of the rest.

If you want to do things manually, you can use

function CreateJSONErrorObject(Const AMessage : String; Const ACode : Integer) : TJSONObject;

// Create a JSON RPC 2 error response object containing an 'Error' object.
// Result is of type TJSONErrorObject
function CreateJSON2ErrorResponse(Const AMessage : String; Const ACode : Integer; ID : TJSONData = Nil; idname : TJSONStringType = 'id' ) : TJSONObject;
function CreateJSON2ErrorResponse(Const AFormat : String; Args : Array of const; Const ACode : Integer; ID : TJSONData = Nil; idname : TJSONStringType = 'id') : TJSONO

These functions from fpjsonrpc.pp return an object and you can do

Response.Content:=MyErr.asJSON;

Michael.



More information about the fpc-devel mailing list