Describe the bug
@sveltejs/kit/src/routing/client.js returns 500 response when certain events happen (too many redirects, failed/timed out fetch, etc.).
|
status: 500, // TODO might not be 500? |
|
status: error instanceof HttpError ? error.status : 500, |
What is the problem?
The 500 code response is supposed to be returned by the server only per HTTP spec "The server has encountered a situation it does not know how to handle." And SvelteKit's server does return 500 for all internal issues. When server cannot be reached, returning "500" from the client-side code is incorrect as it is ambiguous and hides the details that are useful.
In a PWA, when e.g. offline, +error.svelte page cannot distinguish if it was a true server-side error, or if there is no connection to the server for some function that absolutely needs it. In the "no connection" case it would be very useful to be able to show informative message "Cannot perform requested operation when offline. Please connect to the Internet" and possibly "Retry" button and maybe "WiFi Settings" button for mobile devices.
Another problem is lack of detail - 500 covers all bad outcomes on the client side and on the server side. It would be nice to have separate codes for each of the conditions on the client side, so the custom error is only shown for the precise problem.
What codes to show instead?
Any but not 1xx, 2xx, 3xx, 4xx, 5xx that are defined in HTTP spec. HTTP spec does not have status codes for the client-side, it defines conditions only for the server side (4xx codes are called "Client error responses", but in fact all of them are supposed to be returned by the server).
I propose to assign 6xx codes and call them "client fetch" errors. Can be assigned like:
600 - client-side catch-all "The client has encountered a situation it does not know how to handle and has no idea how describe it in English so a 6xx code can be created."
601 - too many redirects
602 - timeout getting server response
603 - error in branch load (can someone propose a better name?)
604 - error when loading error page
605 - error when loading root error page
... other codes if needed.
If that 6xx codes proposal is not workable (e.g. for "breaking change" in release candidate), then add a "client" field (or something similar) with a unique dis-ambiguation code (though I feel this solution is less logical).
Reproduction
I don't feel the repro is needed here.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
Can't make informative "connect to Internet" pages for "offline PWA" mode.
Describe the bug
@sveltejs/kit/src/routing/client.js returns 500 response when certain events happen (too many redirects, failed/timed out fetch, etc.).
kit/packages/kit/src/runtime/client/client.js
Line 291 in a2b9c3e
kit/packages/kit/src/runtime/client/client.js
Line 815 in a2b9c3e
kit/packages/kit/src/runtime/client/client.js
Line 892 in a2b9c3e
kit/packages/kit/src/runtime/client/client.js
Line 1390 in a2b9c3e
kit/packages/kit/src/runtime/client/client.js
Line 1718 in a2b9c3e
What is the problem?
The 500 code response is supposed to be returned by the server only per HTTP spec "The server has encountered a situation it does not know how to handle." And SvelteKit's server does return 500 for all internal issues. When server cannot be reached, returning "500" from the client-side code is incorrect as it is ambiguous and hides the details that are useful.
In a PWA, when e.g. offline, +error.svelte page cannot distinguish if it was a true server-side error, or if there is no connection to the server for some function that absolutely needs it. In the "no connection" case it would be very useful to be able to show informative message "Cannot perform requested operation when offline. Please connect to the Internet" and possibly "Retry" button and maybe "WiFi Settings" button for mobile devices.
Another problem is lack of detail - 500 covers all bad outcomes on the client side and on the server side. It would be nice to have separate codes for each of the conditions on the client side, so the custom error is only shown for the precise problem.
What codes to show instead?
Any but not 1xx, 2xx, 3xx, 4xx, 5xx that are defined in HTTP spec. HTTP spec does not have status codes for the client-side, it defines conditions only for the server side (4xx codes are called "Client error responses", but in fact all of them are supposed to be returned by the server).
I propose to assign 6xx codes and call them "client fetch" errors. Can be assigned like:
600 - client-side catch-all "The client has encountered a situation it does not know how to handle and has no idea how describe it in English so a 6xx code can be created."
601 - too many redirects
602 - timeout getting server response
603 - error in branch load (can someone propose a better name?)
604 - error when loading error page
605 - error when loading root error page
... other codes if needed.
If that 6xx codes proposal is not workable (e.g. for "breaking change" in release candidate), then add a "client" field (or something similar) with a unique dis-ambiguation code (though I feel this solution is less logical).
Reproduction
I don't feel the repro is needed here.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
Can't make informative "connect to Internet" pages for "offline PWA" mode.