0

In my project, there is a RAD Server that handles access to an MSSQL Database. The client fires CRUD operations via REST to that Server, the Server handles the messages.

Now there is a field in a table that is configured as "unique index". When I try to create a row with an existing value in that field, I get a ekUKViolated error message. My question is, how can I pass the error object (not the Message) inside my RAD Server to my client via the REST response? In the REST client, I only get an invalid typecasting error.

Response Code looks like that:

try
  ...
except
  on e: Exception do
  begin
    AResponse.StatusCode := 400;
    AResponse.Body.SetValue(TJSONString.Create(e.Message + ' - ' + e.ClassName), True);
    Exit;
  end;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
fisi-pjm
  • 378
  • 2
  • 16
  • The O in "JSON" stands for "object". Everything must either be an object or at least an array - but you only create a JSON string. Hence, it's not valid JSON. Where's the JSON you respond with for HTTP status 200? – AmigoJack Jul 27 '21 at 10:29
  • 1
    @AmigoJack [Is this simple string considered valid JSON?](https://stackoverflow.com/questions/7487869/is-this-simple-string-considered-valid-json). – Peter Wolf Jul 27 '21 at 10:51
  • @AmigoJack my 200 Response works. There I use a Object, but I don't want to write super specific Code for Error Handeling. I would like sort of Convert my Exception Object into JSON and on the Client Side convert it back into Exception so I can handle Usermessages in GUI. – fisi-pjm Jul 27 '21 at 10:52
  • 1
    Send the error message and then the client can use the message to create an exception. Don't try to recreate the exact same exception object. – Olivier Jul 27 '21 at 11:01

0 Answers0