From 4af5b52bcac25e02f896c9db8a1000079c32ee12 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Tue, 7 Feb 2023 21:12:21 -0500 Subject: [PATCH] 404 --- docz/docs/09-miscellany/02-errors.md | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docz/docs/09-miscellany/02-errors.md b/docz/docs/09-miscellany/02-errors.md index d93206a..5aa5c94 100644 --- a/docz/docs/09-miscellany/02-errors.md +++ b/docz/docs/09-miscellany/02-errors.md @@ -100,6 +100,35 @@ server with NodeJS or some other server-side technology. If the files are small, please [report to our issue tracker](https://git.sheetjs.com/sheetjs/sheetjs/issues) +#### Invalid HTML: could not find table + +Data can be fetched and parsed by the library: + +```js +const response = await fetch("test.xlsx"); +const wb = XLSX.read(await response.arrayBuffer()); +``` + +If the file does not exist, servers will send a 404 response that may include a +friendly HTML page. Without checking the response code, the integration will try +to read the 404 page and fail since the HTML typically has no TABLE elements. + +When building a project with CRA or other templates, spreadsheets must be placed +in the `public` folder. That folder is served by the dev server and copied in +the build process. + +Integration code should defend against network issues by checking status code. +For example, when using `fetch`: + +```js +async function fetch_workbook_and_error_on_404(url) { + const response = await fetch(url); + if(res.status == 404) throw new Error("404 File Not Found"); + const ab = await response.arrayBuffer(); + return XLSX.read(ab); +} +``` + #### SCRIPT5022: DataCloneError IE10 does not properly support `Transferable`.