jpsider / RestPS

Simple ReST Framework for Powershell
MIT License
112 stars 30 forks source link

Response/Return values to API call #62

Closed kmschmehl closed 2 years ago

kmschmehl commented 2 years ago

Hi there -

Thanks for making this module - very useful! I am trying to make a custom failure response if my script meets a certain criteria. Is there any support/examples for returning a non-standard failure response?

jpsider commented 2 years ago

what would you expect the response to look like?

kmschmehl commented 2 years ago

I’d like to provide a custom return from my functions with more descriptive messages. For instance, if I run a try/catch in the catch area I’d like to be descriptive about why the API call failed (couldn’t find object, object already exists, etc) or provide the error message from the API/function that I am calling.

From what I can tell if I return a message/json, the status returned is always 0. I’d like to return a string/json and specify the status code returned.


From: Justin Sider @.> Sent: Monday, November 1, 2021 7:48:32 AM To: jpsider/RestPS @.> Cc: kmschmehl @.>; Author @.> Subject: Re: [jpsider/RestPS] Response/Return values to API call (Issue #62)

what would you expect the response to look like?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/jpsider/RestPS/issues/62#issuecomment-956166232, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHYQY6RRTYJRUC3ZV7MJY4DUJZ5BBANCNFSM5GYWEXVQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jpsider commented 2 years ago

You should be able to achieve this by these two settings in your script: $script:StatusCode $script:StatusDescription