I’m building a Shopify app using Remix. From the frontend, I make a POST request to my API expecting a JSON response. When the API fails (e.g., throws a 500 error), I catch it in my backend and return JSON like this:
return json(
{
success: false,
error: error.message || "Failed to process request"
},
{ status: 500 }
);
However, in the browser, the response is an HTML document, not JSON.
I want to understand:
-
Why Shopify returns HTML on API errors instead of the JSON I send.
-
If there’s a recommended way to ensure the frontend always receives JSON, even when errors occur.
Any insights or best practices would be appreciated.

