Skip to content

Commit 4f78fd7

Browse files
committed
Add Format-RaindropError function for improved error handling and update module version to 1.0.0
1 parent 6b04479 commit 4f78fd7

File tree

7 files changed

+75
-7
lines changed

7 files changed

+75
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function Format-RaindropError {
2+
<#
3+
.SYNOPSIS
4+
Formats detailed error information from a Raindrop API call.
5+
6+
.DESCRIPTION
7+
Extracts HTTP status code, status description, and exception message from an error object
8+
to provide comprehensive error details for Raindrop API failures.
9+
10+
.PARAMETER ErrorRecord
11+
The error record from a catch block.
12+
13+
.PARAMETER Url
14+
The URL that was being accessed when the error occurred.
15+
16+
.PARAMETER Operation
17+
A description of the operation being performed (e.g., "export", "backup").
18+
If not provided, uses the name of the calling cmdlet.
19+
20+
.EXAMPLE
21+
try {
22+
Invoke-RestMethod -Uri $url -Headers $headers -Method Get
23+
}
24+
catch {
25+
Format-RaindropError -ErrorRecord $_ -Url $url
26+
}
27+
#>
28+
param (
29+
[Parameter(Mandatory)]
30+
$ErrorRecord,
31+
32+
[Parameter(Mandatory)]
33+
[string] $Url,
34+
35+
[Parameter(Mandatory = $false)]
36+
[string] $Operation
37+
)
38+
39+
# If Operation not provided, use the calling cmdlet's name
40+
if ([string]::IsNullOrEmpty($Operation)) {
41+
$Operation = (Get-PSCallStack)[1].Command
42+
}
43+
44+
$errorMessage = $ErrorRecord.Exception.Message
45+
$statusCode = $ErrorRecord.Exception.Response.StatusCode.value__
46+
$statusDescription = $ErrorRecord.Exception.Response.StatusDescription
47+
48+
$errorDetails = @()
49+
$errorDetails += "Failed to run '$Operation'"
50+
$errorDetails += "(URL: $Url)"
51+
52+
if ($statusCode) {
53+
$httpStatus = "HTTP $statusCode"
54+
if ($statusDescription) {
55+
$httpStatus += " ($statusDescription)"
56+
}
57+
$errorDetails += $httpStatus
58+
}
59+
60+
$errorDetails += "Message: $errorMessage"
61+
62+
return $errorDetails -join " | "
63+
}

Raindrop.API/Public/Backup/Get-RaindropBackup.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function Get-RaindropBackup {
1212
return $response.items
1313
}
1414
catch {
15-
Write-Error "Failed to retrieve projects: $_"
15+
$errorMsg = Format-RaindropError -ErrorRecord $_ -Url $url
16+
Write-Error $errorMsg
1617
}
1718
}

Raindrop.API/Public/Backup/New-RaindropBackup.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function New-RaindropBackup {
1313
return $response.result
1414
}
1515
catch {
16-
Write-Error "Failed to retrieve projects: $_"
16+
$errorMsg = Format-RaindropError -ErrorRecord $_ -Url $url
17+
Write-Error $errorMsg
1718
}
1819
}

Raindrop.API/Public/Backup/Save-RaindropBackup.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function Save-RaindropBackup {
2727
}
2828
}
2929
catch {
30-
Write-Error "Failed to retrieve projects: $_"
30+
$errorMsg = Format-RaindropError -ErrorRecord $_ -Url $url
31+
Write-Error $errorMsg
3132
}
3233
}

Raindrop.API/Public/Export/Export-Raindrop.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function Export-Raindrop {
4040
}
4141
}
4242
catch {
43-
Write-Error "Failed to retrieve projects: $_"
43+
$errorMsg = Format-RaindropError -ErrorRecord $_ -Url $url
44+
Write-Error $errorMsg
4445
}
4546
}

Raindrop.API/Public/User/Get-RaindropUser.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function Get-RaindropUser {
1212
return $response.user
1313
}
1414
catch {
15-
Write-Error "Failed to retrieve projects: $_"
15+
$errorMsg = Format-RaindropError -ErrorRecord $_ -Url $url
16+
Write-Error $errorMsg
1617
}
1718
}

Raindrop.API/Raindrop.API.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
@{
33
RootModule = 'Raindrop.API.psm1'
4-
ModuleVersion = '0.1.0'
4+
ModuleVersion = '1.0.0'
55
GUID = '051beb040c1c4869a116f1d524b04afc'
66
Author = 'Alan Plocieniak'
77
CompanyName = 'Alan Plocieniak'
8-
Copyright = '(c) 2025 Alan Plocieniak. All rights reserved.'
8+
Copyright = '(c) 2026 Alan Plocieniak. All rights reserved.'
99
Description = 'PowerShell module to interact with the Raindrop.io API'
1010
PowerShellVersion = '5.0'
1111
FunctionsToExport = '*'

0 commit comments

Comments
 (0)