Get-PasswordStatePasswordHistory does not throw.
trir262 opened this issue · 3 comments
trir262 commented
When the function Get-PasswordStatePasswordHistory does not contain a PasswordState or the number is incorrect, Passwordstate returns a NotFound http status code. This error is not captured by the function/module
dnewsholme commented
It seems to throw an error for me.
What scenario are you doing?
PS C:\Users\dnewsholme> Get-PasswordStatePasswordHistory -PasswordID 0
Invoke-RestMethod : [{"errors":[{"message":"Not Found"},{"phrase":"A Password of ID '0' was not found in the database, or you do not have permissions to it."}]}]
At line:94 char:27
+ ... $result = Invoke-RestMethod @params -UseDefaultCredentials -Timeout ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Method: GET, Reques\u2026ZXTWHXz1zQH3VmoE
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Method invocation failed because [System.Object[]] does not contain a method named 'DecryptPassword'.
At line:45 char:17
+ $output.DecryptPassword()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
trir262 commented
Hi @dnewsholme, the displayed error is actually from Invoke-RestMethod (web response NotFound). It would be better (imho) to catch that error and throw a more meaningfull message (perhaps use the message in 'phrase' as exceptino message)
dnewsholme commented
Fixed in #92