You are not logged in.
Pages: 1
Hello!
I have a simple TSQLRecord class with one unique field:
type
TCategory = class(TSQLRecord)
private
FName: RawUTF8;
published
property Name: RawUTF8 index 64 read FName write FName stored AS_UNIQUE;
end;
If ajax post request is performed with "Name" value wich is already exists, the server respones with such answer:
{
"errorCode":400,
"errorText":"Bad Request"
}
And there is no detail info on what was wrong. I tried to use validators to get more relevant answer(for example "errorText":"Name field must be unique") but with no luck. As I understood to use a validator I have to define my own server method and explicitly call Rec.Validate method. Am I right? And what is the right way to perform filter and validation while working with ajax client?
Many thanks in advance!
Offline
I had a similar problem with a service and chose 409 as the http error code. I'm a bit confused with how to handle mORMot errors with ajax. Are errors within mORMot only returned with an ok 200 response with the error encoded as JSON within the response or does it use http error codes?
Offline
Well, I think the best idea is to have a possibility to add a validator on server side, wich will process the requests and responses with custom json or at least with custom error message like "errorText":"'Name' field must be unique".
As I know usually "422 Unprocessable Entity" or "409 Conflict" errors are used in such case.
Offline
The solution is very easy: drop the unique index, and the ajax request has no error anymore.
Offline
Pages: 1