capacitor-community / capacitor-community/sqlite
bug: [Web] CapacitorSQLite.getFromHTTPRequest resolves on 200 with empty body and “hangs” on 404
- Dominant language
- Swift
- Stars
- 661
- Forks
- 158
- PR merge metrics
- No merged PRs in 30d
Description
**Plugin version:**
`@capacitor-community/sqlite` **7.0.0**
**Platform(s):**
Web (tested on Chrome 139, Windows 10).
(App works differently on native; issue appears specific to Web.)
**Current behavior:**
* When the URL returns **HTTP 200** with an **empty body** (e.g., `Content-Length: 0`), `CapacitorSQLite.getFromHTTPRequest(options)` **resolves** without error even though nothing is downloaded/imported.
* When the URL returns **HTTP 404**, the Promise **neither resolves nor rejects** (appears to hang/freezes), leaving the caller waiting indefinitely.
**Expected behavior:**
* On **non-OK responses** (e.g., 404), the Promise should **reject** with a meaningful error (e.g., `HTTP 404`).
* On **200 with empty body** (`Content-Length: 0` or `blob.size === 0`), the Promise should **reject** (e.g., `Empty response body`) because there is nothing to import.
* Ideally, minimal **content validation** (when expecting a DB/ZIP) should prevent a false positive “success.”
**Steps to reproduce:**
1. Run the app on **Web** (not installed PWA).
2. Call `getFromHTTPRequest` with a URL that returns **200** but **empty body**, e.g. `https://httpbin.org/bytes/0`.
3. Call it again with a URL that returns **404**, e.g. `https://httpbin.org/status/404`.
4. Observe that the first call resolves “success” despite no data; the second call never resolves or rejects.
**Related code:**
```ts
import { CapacitorSQLite, capSQLiteHTTPOptions } from '@capacitor-community/sqlite';
async function test(url: string) {
const options: capSQLiteHTTPOptions = {
url,
overwrite: true,
};
console.time(url);
try {
await CapacitorSQLite.getFromHTTPRequest(options);
console.log('RESOLVED (unexpected if empty body or 404):', url);
} catch (err) {
console.error('REJECTED (expected on HTTP errors or empty body):', url, err);
} finally {
console.timeEnd(url);
}
}
// A) 200 with empty body
test('https://httpbin.org/bytes/0'); // 200 OK, Content-Length: 0
// B) 404
test('https://httpbin.org/status/404'); // 404 Not Found
```
**Other information:**
* Browser: Chrome **139** on Windows 10.
* Framework: Ionic/Angular **\[please fill]**.
* Repro was done “from web”; not an installed PWA.
* With generic pages that return **200** but not a valid DB/ZIP (e.g., `https://www.google.com`), the call can also **resolve**, suggesting missing content validation on Web.
* CORS: endpoints with CORS disabled correctly throw CORS errors (unrelated); the bug here is about **reachable** URLs returning 200/404.
* Likely Web-only: `fetch` doesn’t throw on 404 (`ok === false`), so explicit handling and/or a timeout/`AbortController` might be missing in the Web implementation.
Contributor guide
Assessment
This issue has not been assessed yet.