SmartResponse-Framework / SmartResponse.Framework

PowerShell module for developing LogRhythm SmartResponse Plugins
Other
8 stars 2 forks source link

Standardize "Catch" blocks for Web Requests #6

Closed GeneCupstid closed 4 years ago

GeneCupstid commented 4 years ago

Guideline for Catching Rest Errors

Use the Get-RestErrorMessage function to extract the relevant error information and throw a generic [System.Exception].

For LogRhythm REST Errors use the following format:

$Err = Get-RestErrorMessage $_
throw [Exception] "[$Me] [$($Err.statusCode)]: $($Err.message) - $($Err.details) - $($Err.validationErrors)"
throw [Exception] "[$Me] [$($Err.code)]: $($Err.message)"

More Info

Some of the functions in SRF may not use the right error property names - initially I assumed they would always be the same, and that is not the case. Ideally we will test error messages to ensure the right information is being reported when an error occurs.

Some Rest Error messages use different fields - for example:

I've seen $Err.error, $Err.error_description, $Err.code, $Err.statusCode and sometimes there is an extra container object like $Err.error.code.

GeneCupstid commented 4 years ago

Closing - replaced by #21