Skip to content

Commit

Permalink
Improve error reporting
Browse files Browse the repository at this point in the history
* Now return the error message from the Microsoft server where possible (See #52)
  • Loading branch information
pbatard committed Jan 6, 2023
1 parent c34a41f commit 84f833b
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions Fido.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Fido v1.37 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2022 Pete Batard <pete@akeo.ie>
# Fido v1.38 - Feature ISO Downloader, for retail Windows images and UEFI Shell
# Copyright © 2019-2023 Pete Batard <pete@akeo.ie>
# Command line support: Copyright © 2021 flx5
# ConvertTo-ImageSource: Copyright © 2016 Chris Carter
#
Expand Down Expand Up @@ -499,7 +499,7 @@ function ConvertTo-ImageSource

function Throw-Error([object]$Req, [string]$Alt)
{
$Err = $(GetElementById -Request $r -Id "errorModalMessage").innerText
$Err = $(GetElementById -Request $Req -Id "errorModalMessage").innerText -replace '<[^>]+>',''
if (-not $Err) {
$Err = $Alt
} else {
Expand Down Expand Up @@ -824,7 +824,14 @@ function Get-Windows-Download-Links([int]$SelectedVersion, [int]$SelectedRelease
$sr = New-Object System.IO.StreamReader($wr.GetResponse().GetResponseStream())
$r = $sr.ReadToEnd()
if ($r -match "errorModalMessage") {
Throw-Error -Req $r -Alt "Could not retrieve architectures from server"
$regex = New-Object Text.RegularExpressions.Regex '<p id="errorModalMessage">(.+?)<\/p>'
$m = $regex.Match($r)
# Make the typical error message returned by Microsoft's servers more presentable
$Alt = $m.Groups[1] -replace '<[^>]+>' -replace ' Microsoft Support – Contact Us ',' "Microsoft Support – Contact Us" ' -replace ' and$','.'
if (-not $Alt) {
$Alt = "Could not retrieve architectures from server"
}
Throw-Error -Req $r -Alt $Alt
}
$pattern = '(?s)(<input.*?></input>)'
ForEach-Object { [regex]::Matches($r, $pattern) } | ForEach-Object { $html += $_.Groups[1].value }
Expand Down Expand Up @@ -1192,8 +1199,8 @@ exit $Exit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