-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better rest error handling for 5.1 #33
Comments
The error on core comes from the response body nested under result. On 5.1 only the typical header error is shown not the response. It would be useful to parse these and display them correctly for both core and 5.1 |
Also needs checking all commands should throw a readable exception if there are permission/authorization errors. |
I've forced an error in 5.1 (400 bad request), checking the full exception object from both invoke-webrequest and invoke-restmethod still doesnt show any further detail than this.
Under the ErrorDetails inside the exception. I think it's not going to be a straight forward one so I'll leave this for now. |
Hey Tom 👋, 5.1 will stop short of reading the full response body when it gets an error and will instead just read the headers. If, as in the case of ServiceNow, those headers don't contain too much useful info - you can get to the full response stream and decode it yourself by doing something like: try {
# ServiceNow Failing Rest Call Here
} catch {
$StreamReader = New-Object System.IO.StreamReader -argumentList ($_.Response.GetResponseStream());
$ErrorBody = $StreamReader.ReadToEnd()
$StatusCode = [int] $_.Exception.Response.StatusCode
$StatusDescription = $_.Exception.Response.StatusDescription + " " + $ErrorBody
} I've not tested the above (it's from an old ServiceNow script of mine actually) but it should point you in the right direction. Cheers |
@liamjpeters Hey, thanks for this comment, interesting, I'll take a closer look this next week, haven't unfortunately had much chance of late! Hope things are going well! |
If using core you'll get a relevant error from a bad rest request including the error message.
example:
On 5.1 errors are basic and messages not displayed:
example:
Enhancing the error handling and output would be a better user experience on 5.1
The text was updated successfully, but these errors were encountered: