Returning a 401 using %REST.Impl
Hello
I am trying to convert some old rest classes using the OpenApi spec (e.g. %REST.Impl)
Say I want to return a 401 in my impl.cls for api and I can define the status code as follows, e.g.
Do ..%SetStatusCode("401")
Do ..%SetContentType("application/json")However the api client will see this as 401 OK which is not right.
In the past, I could just create a rest class that extends from %CSP.REST and return as follows:
Set%response.Status = ..#HTTP401UNAUTHORIZEDThis will return 401 Unauthorized, which what I expect to see reported in the api client.
How this possible to achieve the same behaviour %REST.Impl? I can't see a method that supports this.
Thanks
Dan
Comments
@Daniel Bertozzi
You can do the following:
Do ..%SetStatusCode(##class(%CSP.REST).#HTTP401UNAUTHORIZED)When you see something that starts with a ..# that's a parameter that's defined in a class. If you look at the source of the %CSP.REST class, you'll see:
Parameter HTTP401UNAUTHORIZED As %String = "401 Unauthorized";
So you could try either set the %response.Status "401 Unauthorized" or add that parameter to your class and use it as you have before in %CSP.REST classes.
Using %CSP.REST class to get value will work. It's a bit weird that %REST.Impl does not have this out of the box though. My guess there's probably an expectation to have an IAM in front of this (e.g. Kong or MS Azure)