I have a very simple Compute example based off of both the Rust and JavaScript starter projects.
I have two backends, one is httpbin and one is a shopify mock data endpoint. I’m testing with these two backend URL / paths specifically:
https://httpbin.org/anything/asdfasdfasdfsda
and
https://mock.shop/api?query=%7B%20product(id%3A%20%22gid%3A%2F%2Fshopify%2FProduct%2F7982905098262%22)%20%7B%20id%20title%20description%20featuredImage%20%7B%20id%20url%20%7D%20%7D%7D
The httpbin response is completely fine and I have no issues accessing the response body with .json(), however I’m having issues with the shopify endpoint for reasons I don’t understand
I’ve tested this with both Rust and JavaScript, but I’ll stick with JavaScript error messages for now.
When I attempt to read the response body as JSON, e.g.
...snip snip...
async function handleRequest(event) {
... snip snip...
backendResponse = await fetch(event.request, {
backend: "shopify",
});
const backendResponseBody = await backendResponse.json();
(or as .text()
)
I see something like this:
Error while running request handler: malformed UTF-8 character sequence at offset 1
Stack:
handleRequest@<stdin>:1608:61
async*bin/index.js/<@<stdin>:1513:64
I’ll add that if I don’t attempt to read the response body (e.g. I don’t do await backendResponse.json();
) and simply return the backend response directly then I see no error, and the response is correct as I’d expect to see it.
For the particular use case I’m investigating I need to be able to access and modify this response body, so I need to be able to read it somehow. Note that httpbin and the shopify mock api are just for examples that I can share.
Am I missing something? Originally I ran into the issue with Rust and assumed it was my rusty Rust that I was running into the issue, but again the same error in the same situations seems to be happening in JS / WASM.
Thanks for any advice!