Skip to content

ui: simplify network error handling#23431

Merged
allozaur merged 1 commit into
ggml-org:masterfrom
socram8888:weberr
Jun 2, 2026
Merged

ui: simplify network error handling#23431
allozaur merged 1 commit into
ggml-org:masterfrom
socram8888:weberr

Conversation

@socram8888

Copy link
Copy Markdown
Contributor

Previously error to string conversion was split in two different files, with one converting errors into strings, and another function analyzing those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and uses directly HTTP error codes whereas possible to generate the human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend, such as "Invalid API key", would get turned incorrectly in to "Failed to connect to server" due to poor matching logic in the now-gone getErrorMessage function, as any error not contemplated by the .includes() would fallback to that generic confusing error message.

@socram8888 socram8888 requested a review from a team as a code owner May 20, 2026 17:00

@allozaur allozaur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! It's a great opportunity to do a bit more in-depth refactor of error handling :) I was planning to have dedicated error classes for different types of errors in the app in order to have this properly structured and more easily debuggable.

Are you up to it? Or you'd rather focus on just shipping this one improvement?

@socram8888

Copy link
Copy Markdown
Contributor Author

I'm not sure if I'd be capable of refactoring this properly - I have absolutely never ever dealth with Svelte, and I don't have a proper environment for huge modifications (this was done on a GPU-equipped machine via SSH and nano!).

Ideally I'd prefer to have this merged (specially to fix the error regarding improper error reporting with Failed to connect to server), and maybe you or I can look further into improving that later once I get a proper setup for larger changes?

@allozaur

Copy link
Copy Markdown
Contributor

I'm not sure if I'd be capable of refactoring this properly - I have absolutely never ever dealth with Svelte, and I don't have a proper environment for huge modifications (this was done on a GPU-equipped machine via SSH and nano!).

Ideally I'd prefer to have this merged (specially to fix the error regarding improper error reporting with Failed to connect to server), and maybe you or I can look further into improving that later once I get a proper setup for larger changes?

Okay, no pressure, will get back to this PR tomorrow then.

Comment thread tools/ui/src/lib/utils/api-fetch.ts
Comment thread tools/ui/src/lib/utils/api-fetch.ts Outdated
Comment thread tools/ui/src/lib/utils/api-fetch.ts Outdated
Comment thread tools/ui/src/lib/utils/api-fetch.ts Outdated
@socram8888

socram8888 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

I've took care of all the issues, except the e instanceof Error ? e : new Error(String(e)) which I'm fairly sure it's redundant.

EDIT: I stand corrected - I forgot how unserious JS is and discovered you can apparently just throw "whatever";. While fetch standard never throws anything but TypeError or RangeError, it may rethrow the abort signal if a request is aborted, and that may not be an Error.

I made beautifyNetworkError accept an any and check the type inside, casting to String if not Error.

@socram8888 socram8888 force-pushed the weberr branch 2 times, most recently from fa0f0f3 to aaca5ac Compare May 21, 2026 12:59
@allozaur

Copy link
Copy Markdown
Contributor

@socram8888 plz fix the linting/formatting so that the CI checks pass :)

@socram8888

Copy link
Copy Markdown
Contributor Author

@allozaur should be GTG now.

@allozaur

Copy link
Copy Markdown
Contributor

@allozaur should be GTG now.

some checks still not passing

Zrzut ekranu 2026-05-25 o 15 14 46

@socram8888

Copy link
Copy Markdown
Contributor Author

@allozaur I had missed the npm run-s check script. Should be passing now ;)

@allozaur

Copy link
Copy Markdown
Contributor

@socram8888 hmm, linting is still not passing on the CI here on GH, please re-check

@allozaur

Copy link
Copy Markdown
Contributor

@socram8888 let's aim to have this merged soon :) please let me know if u can take care of the CI failing on linting

@allozaur allozaur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the lint in CI

Previously error to string conversion was split in two different files,
with one converting errors into strings, and another function analyzing
those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and
uses directly HTTP error codes whereas possible to generate the
human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend,
such as "Invalid API key", would get turned incorrectly in to
"Failed to connect to server" due to poor matching logic in the
now-gone getErrorMessage function.
@socram8888

Copy link
Copy Markdown
Contributor Author

@allozaur Done. Both npm run lint and npm run check pass flawlessly now.

@allozaur allozaur merged commit 69cea5b into ggml-org:master Jun 2, 2026
6 checks passed
jimbothigpen pushed a commit to jimbothigpen/llama.cpp that referenced this pull request Jun 6, 2026
Previously error to string conversion was split in two different files,
with one converting errors into strings, and another function analyzing
those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and
uses directly HTTP error codes whereas possible to generate the
human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend,
such as "Invalid API key", would get turned incorrectly in to
"Failed to connect to server" due to poor matching logic in the
now-gone getErrorMessage function.

(cherry picked from commit 69cea5b)
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Jul 3, 2026
Previously error to string conversion was split in two different files,
with one converting errors into strings, and another function analyzing
those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and
uses directly HTTP error codes whereas possible to generate the
human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend,
such as "Invalid API key", would get turned incorrectly in to
"Failed to connect to server" due to poor matching logic in the
now-gone getErrorMessage function.
adrianhoehne pushed a commit to adrianhoehne/llama.cpp that referenced this pull request Jul 5, 2026
Previously error to string conversion was split in two different files,
with one converting errors into strings, and another function analyzing
those strings to generate yet another string.

Now the the error handling for network fetches has been centralised and
uses directly HTTP error codes whereas possible to generate the
human-readable error strings.

It also fixes an issue where all JSON errors reported from the backend,
such as "Invalid API key", would get turned incorrectly in to
"Failed to connect to server" due to poor matching logic in the
now-gone getErrorMessage function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants