Is it possible to change the Response Code when user authorization fails in a datasnap server?
Asked Answered
C

2

5

Is it possible to change the HTTP Response Code in my DataSnap (Delphi XE3) server when user authorization fails? Currently it's returning HTTP/1.1 500 Internal Server Error, which can happen in many other scenarios, and doesn't help describe the problem.

Along the same idea, is it possible to change the default Response Body? Currently, it's returning {"error":"USER is not authorized to perform the requested action."}, which is fine, but I'd like to return a custom JSON object if possible.

Thanks for your time!

Coccus answered 21/5, 2013 at 16:10 Comment(0)
C
5

I ended up executing code that looked like this in TDSAuthenticationManager.OnUserAuthorize


  if valid = false then
  begin
    GetInvocationMetadata.ResponseCode := 403;
    GetInvocationMetadata.ResponseMessage := JSONResponseObject.ToString;
    GetInvocationMetadata.ResponseContent := JSONResponseOjbect.ToString;
  end
Coccus answered 19/9, 2013 at 22:29 Comment(0)
B
2

It's possible to get the THTTPDSResponse inside a serverclass? Ex:

TServerClass1.EchoString(val: string);
begin
  GetDSResponse.Header.Add('someheader');
end;
Bui answered 21/5, 2015 at 18:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.