how can i set the return http code for a reslet
# suitescript
s
how can i set the return http code for a reslet
c
I don't believe it's possible, except maybe for forcing a 400 with an uncaught error. What we do is wrap our responses like so:
Copy code
{
  code: 404,
  data: {}
}
then the application calling it unwraps it and handles it accordingly.
I suppose you could try setting a custom header instead - haven't tried that yet
s
it doesn't work as the receiving application will check the HTTP code which is 200
c
@Sim Greenbaum Do you have any control over that application?
For cases where I don't have control over the receiving application, I've built a Google Cloud function relay - that relay accepts requests from the receiving application, forwards it to Netsuite, unwraps the response, and replies to the application with the appropriate status code.
s
I figured it out I was catching the error inside my reslet instead let the error go and NetSuite set the code to 400
🌟 1
s
don't
catch
unless you have have a legit reason to do so.
💯 1
c
@Shawn Talbert I might refine that a bit by suggesting that you catch and analyze errors, then throw the ones you want to throw
s
if you have something meaningful to do with the exception then sure, that's what
catch
is for 🙂
I've seen far too many scripts with copious try/catch blocks that simply swallow errors
c
same
s
i wanted to catch it and handle the http response but not catching is the way to go
🙌 2