Endpoints returning 500 errors and TypeErrors in console [edit: headers to blame?!]

Product: PowerShell Universal
Version: 3.5.3

Installation type is Windows - MSI
PSU primary base dir has been moved to E:\PSU\RepositoryInternals
HTTPS is enabled via PKI-issued cert

I am having multiple issues with APIs since updating to 3.5.3 last night. What was working fine is now returning a 500 error from external requests. Just a 500, not QUITE instantly, but nothing else.

Testing in API details from the admin site gives this error:

TypeError: (intermediate value)(intermediate value)(intermediate value).create is not a function

    at pe (https://eedevops/admin/static/js/0.cf1b51ae.chunk.js:1:12079)
    at N (https://eedevops/admin/static/js/33.7c7f00fb.chunk.js:1:13716)
    at K (https://eedevops/admin/static/js/33.7c7f00fb.chunk.js:1:8335)
    at div
    at div
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3389067
    at n (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3109673)
    at Suspense
    at u (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:52982)
    at E (https://eedevops/admin/static/js/75.503d1758.chunk.js:1:446)
    at div
    at d (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:974401)
    at div
    at t.b (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:975384)
    at div
    at div
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3389067
    at div
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:1008601
    at F (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:90333)
    at div
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3009876
    at T (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:89963)
    at n (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3109673)
    at Suspense
    at u (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:52982)
    at m (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:89459)
    at g (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:89637)
    at B (https://eedevops/admin/static/js/33.7c7f00fb.chunk.js:1:1518)
    at d (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389246)
    at p (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389574)
    at c
    at d (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389246)
    at p (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389574)
    at n (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3109673)
    at Suspense
    at u (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:52982)
    at main
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:911817
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:911648
    at section
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:912052
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:911648
    at div
    at div
    at t (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:2880341)
    at ve (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:140933)
    at section
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:912052
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:911648
    at section
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:912052
    at https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:911648
    at Bt (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:159506)
    at d (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389246)
    at p (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389574)
    at h (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:389311)
    at u (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:377284)
    at n (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:3109673)
    at Suspense
    at u (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:52982)
    at m (https://eedevops/admin/static/js/main.899d13a6.chunk.js:1:131891)
    at s (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:940449)
    at c (https://eedevops/admin/static/js/17.a9efa917.chunk.js:2:665677)
    at va

It’s not clear if the same cause underlies both behaviors - I see a similar TypeError was reported and marked solved in June. If they’re separate, the only one I REALLY care about is the 500 error when using the API via HTTP requests.

A newly-created endpoint works without any issues, but I’d really like to avoid having to recreate these, and it seems reusing the “API path” is what leads to the issues. [EDIT: ha, nope, see reply]

It seems like something is getting stuck somewhere. None of this helps:

  1. Changing endpoint path
  2. Changing endpoint environment
  3. Toggling endpoint persistent logging
  4. Restarting APIs via button on Endpoints
  5. Restarting PSU service

Endpoint code (I excised the actual function but the behavior from PSU is the same) from endpoints.ps1:

New-PSUEndpoint -Url "/api/util/flip/:text" -Description "Flips text." -Method @('GET') -Endpoint {
param (
    [parameter()]
    [string]$Text
)

$Output = "Flipping: $Text"

New-PSUApiResponse -Body $Output -StatusCode 200 -Headers @{"content-type"="application/json;charset=UTF-8"}
} -Environment "Windows PowerShell 5.1" 

All the endpoints are in endpoints.ps1 under .universal, nothing weird there.

Thanks!

Okay, I’ve just found out exactly what’s triggering this: headers. It seems the headers that used to function without issue now cause some kind of parsing error in the PSU engine.

If I comment out and remove the Headers on New-PSUApiResponse it works fine.

So this (as the endpoint code) works:


param (
    [parameter()]
    [string]$Text
)

if ($Text) {
    $Output = "(╯°□°)╯ ︵  $Text"
    New-PSUApiResponse -Body "$Output" -StatusCode 200 #-Headers @{'content-type'='application/json; charset=UTF-8'}
} else {
    throw "Invalid params!"    
}

And this doesn’t:


param (
    [parameter()]
    [string]$Text
)

if ($Text) {
    $Output = "(╯°□°)╯ ︵  $Text"
    New-PSUApiResponse -Body "$Output" -StatusCode 200 -Headers @{'content-type'='application/json; charset=UTF-8'}
} else {
    throw "Invalid params!"    
}

(Please don’t judge the meme lol - this is my go-to for validation and testing charsets/unicode output)

I think this is because Content-Type is being set twice. Try using the -ContentType parameter instead.


param (
    [parameter()]
    [string]$Text
)
    $Output = "(╯°□°)╯ ︵  $Text"
    New-PSUApiResponse -Body "$Output" -StatusCode 200  -ContentType 'application/json; charset=UTF-8'

1 Like

And that did it! Did not realize that had to be a separate param and not a header. It was working til recently. Thanks @adam , you are awesome!

1 Like