analyze_errors_v2.ps1 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # Analyze 404 and 500 errors in detail - categorize root causes
  2. $companyUrl = "http://localhost:8006"
  3. # Login
  4. $loginBody = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
  5. $loginResp = Invoke-WebRequest -Uri "$companyUrl/login" -Method POST -ContentType "application/json" -Body $loginBody -UseBasicParsing
  6. $loginJson = $loginResp.Content | ConvertFrom-Json
  7. $token = $loginJson.token
  8. Write-Host "Token OK"
  9. $headers = @{ Authorization = "Bearer $token" }
  10. # Read the test results
  11. $content = Get-Content "d:\ylrz\saasadminui\api_test_results.txt" -Raw
  12. $sections = $content -split "=== "
  13. # Parse 404 and 500
  14. $notFound = @()
  15. $serverErr = @()
  16. foreach ($section in $sections) {
  17. if ($section.StartsWith("404 Not Found")) {
  18. $notFound = ($section -split "`n" | Where-Object { $_.Trim() -ne "" -and $_ -notmatch "^404 Not Found" })
  19. } elseif ($section.StartsWith("500 Server Error")) {
  20. $serverErr = ($section -split "`n" | Where-Object { $_.Trim() -ne "" -and $_ -notmatch "^500 Server Error" })
  21. }
  22. }
  23. # Analyze 404: categorize by issue type
  24. Write-Host "=== 404 Analysis ==="
  25. Write-Host "Total 404s: $($notFound.Count)"
  26. # Category 1: Trailing / paths (e.g. /ad/ vs /ad)
  27. $trailingSlashPaths = $notFound | Where-Object { $_ -match "//\s" -or $_ -match "/\s+\|" }
  28. Write-Host "Trailing slash paths: $($trailingSlashPaths.Count)"
  29. # Category 2: CamelCase entity paths (e.g. /ad/AdDyAccount vs /ad/adDyAccount)
  30. $camelCasePaths = $notFound | Where-Object { $_ -match "/[A-Z][a-z]+[A-Z]" }
  31. Write-Host "CamelCase entity paths: $($camelCasePaths.Count)"
  32. # Category 3: Module paths that might not exist
  33. $modulePaths = @{}
  34. foreach ($line in $notFound) {
  35. if ($line -match "^\s*/([^/]+)/") {
  36. $mod = $Matches[1]
  37. if (-not $modulePaths.ContainsKey($mod)) { $modulePaths[$mod] = 0 }
  38. $modulePaths[$mod]++
  39. }
  40. }
  41. # Test some specific 500 errors to understand the error message
  42. Write-Host "`n=== Sample 500 Error Details ==="
  43. $sample500 = $serverErr | Select-Object -First 10
  44. foreach ($line in $sample500) {
  45. if ($line -match "^\s*(/\S+)") {
  46. $path = $Matches[1]
  47. try {
  48. $resp = Invoke-WebRequest -Uri "$companyUrl$path" -Method GET -Headers $headers -UseBasicParsing -TimeoutSec 5
  49. $body = $resp.Content | ConvertFrom-Json
  50. Write-Host "$path => code=$($body.code) msg=$($body.msg)"
  51. } catch {
  52. $err = $_.Exception.Message
  53. if ($err -match "500") {
  54. # Try to get response body for 500
  55. try {
  56. $errResp = Invoke-WebRequest -Uri "$companyUrl$path" -Method GET -Headers $headers -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop
  57. Write-Host "$path => $($errResp.Content.Substring(0, [Math]::Min(200, $errResp.Content.Length)))"
  58. } catch {
  59. Write-Host "$path => HTTP 500 (no response body available)"
  60. }
  61. } else {
  62. Write-Host "$path => $err"
  63. }
  64. }
  65. }
  66. }
  67. # Test some specific 404 errors to understand
  68. Write-Host "`n=== Sample 404 Error Details ==="
  69. # Test /ad module paths (case sensitivity check)
  70. $testCases = @(
  71. "/ad/AdDyAccount/list",
  72. "/ad/adDyAccount/list",
  73. "/ad/ad_dy_account/list",
  74. "/his/doctor/list",
  75. "/his/doctor/export",
  76. "/his/healthRecord/list",
  77. "/his/healthrecord/list",
  78. "/company/companyUser/list",
  79. "/companyUser/list",
  80. "/store/store/list",
  81. "/store/storeProduct/list",
  82. "/course/courseDomainName/list"
  83. )
  84. foreach ($path in $testCases) {
  85. try {
  86. $resp = Invoke-WebRequest -Uri "$companyUrl$path" -Method GET -Headers $headers -UseBasicParsing -TimeoutSec 5
  87. $body = $resp.Content | ConvertFrom-Json
  88. Write-Host "$path => code=$($body.code) msg=$($body.msg)"
  89. } catch {
  90. $err = $_.Exception.Message
  91. if ($err -match "(\d{3})") {
  92. Write-Host "$path => HTTP $($Matches[1])"
  93. } else {
  94. Write-Host "$path => $err"
  95. }
  96. }
  97. }
  98. # Count 404 paths that have a corresponding path with different casing
  99. Write-Host "`n=== Case Sensitivity Check ==="
  100. $lowercasePaths = @{}
  101. foreach ($line in $notFound) {
  102. if ($line -match "^\s*(/\S+)") {
  103. $path = $Matches[1]
  104. $lower = $path.ToLower()
  105. if (-not $lowercasePaths.ContainsKey($lower)) {
  106. $lowercasePaths[$lower] = @()
  107. }
  108. $lowercasePaths[$lower] += $path
  109. }
  110. }
  111. $caseConflicts = $lowercasePaths.GetEnumerator() | Where-Object { $_.Value.Count -gt 1 }
  112. Write-Host "Paths with case variants: $($caseConflicts.Count)"
  113. $caseConflicts | Select-Object -First 10 | ForEach-Object {
  114. Write-Host " $($_.Key): $($_.Value -join ', ')"
  115. }