csaf-poc / csaf_webview

Web app (module) to display a CSAF 2 document and to browse CSAF 2 ROLIE feeds. ⚠️ The web demo is often not allowed to access servers:
https://csaf-poc.github.io/csaf_webview/
1 stars 3 forks source link

deal with all error cases when getting an url #23

Closed bernhardreiter closed 8 months ago

bernhardreiter commented 8 months ago

According to https://developer.mozilla.org/en-US/docs/Web/API/fetch we need to deal with exceptions and with different response codes in case response.ok == false.

Dot get done in lib/urloader.ts

ThomasJunk commented 8 months ago

This may be not possible:

which both does not allow to differentiate further although the documentation suggests otherwise.

Having looked at Stack Overflow I found this:

As a client of fetch, you can't differentiate network errors from other errors caused by building an incorrect request, as both are thrown as TypeErrors. (See https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions). This is quite a flaw, as application defects that cause an incorrectly built request may go unnoticed, masked as if they were circumstantial network errors.

Which basically says the same I experienced. So I leave a "general" error handler for these cases. But otherwise implemented messages distinguishing between the typical 401, 403, 404.

bernhardreiter commented 8 months ago

Meanwhile improved by @ThomasJunk by dealing with response code. @JanHoefelmeyer did you test that other error message work already?

JanHoefelmeyer commented 8 months ago

Error-responses will be handled as expected:

An error will cause an error Text to appear, detailing the status code and statustext (if any).