45 lines
1.5 KiB
Markdown
45 lines
1.5 KiB
Markdown
|
---
|
||
|
title: 'Solving "XML Parsing Error: no root element found" in Firefox'
|
||
|
date: 2022-12-17T21:27:37-05:00
|
||
|
toc: false
|
||
|
images:
|
||
|
tags:
|
||
|
- dev
|
||
|
- web
|
||
|
---
|
||
|
|
||
|
I've been seeing this error a lot while working on my project [Bulgur Cloud](/bulgur-cloud-intro/).
|
||
|
It seems to show up only on Firefox:
|
||
|
|
||
|
![Error message in Firefox console. "XML Parsing Error: no root element found. Location: http://...701.jpg Line Number 1, Column 1](/img/2022-12-17.firefox.xml-parsing-error.png)
|
||
|
|
||
|
What is curious was that I was not actually loading the file mentioned in the
|
||
|
error message. I tried looking up what the error might mean, but all that came
|
||
|
up was very specific issues regarding some web frameworks, unrelated to what I'm
|
||
|
using.
|
||
|
|
||
|
I later realized however, while I wasn't loading the file in the error message,
|
||
|
I was actually sending a `DELETE` request. The Bulgur Cloud server then responds
|
||
|
to this request with an empty `200 OK` response. Turns out, if you send an empty
|
||
|
response to Firefox, it tries to parse the body of the response even though it's
|
||
|
empty and gives you this error.
|
||
|
|
||
|
To quiet this error, I started just sending an empty JSON response even for
|
||
|
requests that don't actually need it. Here's some rust code to illustrate the
|
||
|
solution:
|
||
|
|
||
|
```rust
|
||
|
#[derive(Debug, Serialize)]
|
||
|
pub struct EmptySuccess {
|
||
|
status: &'static str,
|
||
|
}
|
||
|
|
||
|
// Using actix-web
|
||
|
fn empty_ok_response() -> HttpResponse {
|
||
|
HttpResponse::Ok().json(EmptySuccess { status: "ok"})
|
||
|
}
|
||
|
```
|
||
|
|
||
|
This adds a `{"status": "ok"}` json to the response, which seems to be enough to
|
||
|
make Firefox happy.
|