D
Deno

help

Error only happens when I'm on deno deploy

EEGamalielGZ10/6/2023
Please can someone explain why with my web application when deployed in deno deploy I get this response and error when trying to login but not when I login locally? Response: Response { body: ReadableStream { locked: false }, bodyUsed: false, headers: Headers { "content-length": "98", "content-type": "text/plain; charset=utf-8", date: "Fri, 06 Oct 2023 03:51:17 GMT", server: "deno/gcp-us-south1", via: "http/1.1 edgeproxy" }, ok: false, redirected: false, status: 508, statusText: "Loop Detected", url: "https://roomhome.deno.dev/api/auth/client/login" } Error: An error occurred during route handling or page rendering. SyntaxError: Unexpected non-whitespace character after JSON at position 3 (line 1 column 4) at parse (<anonymous>) at packageData (ext:deno_fetch/22_body.js:369:14) at consumeBody (ext:deno_fetch/22_body.js:246:12) at eventLoopTick (ext:core/01_core.js:183:11) at async POST (file:///src/routes/login.tsx:40:32) at async handler (file:///src/routes/_middleware.ts:32:14) at async handler (https://deno.land/x/fresh@1.4. Repo: https://github.com/EGAMAGZ/RoomHome
GitHub
GitHub - EGAMAGZ/RoomHome: Tienda de inmobilaria
Tienda de inmobilaria. Contribute to EGAMAGZ/RoomHome development by creating an account on GitHub.
DAHDeno AI Helper10/6/2023
Based on the error message you provided, it seems like the issue is related to parsing JSON data. The error message Unexpected non-whitespace character after JSON at position 3 (line 1 column 4) typically indicates that the JSON data you're trying to parse is not formatted correctly. The error occurs at file:///src/routes/login.tsx:40:32, which suggests that the issue is in your login.tsx file at line 40, column 32. Unfortunately, without access to your code, it's hard to provide a more specific solution. However, the documentation provides some general advice for handling errors in Deno: 1. Check the JSON data: Make sure the JSON data you're trying to parse is correctly formatted. You can use online JSON validators to check this. 2. Handle potential errors: The req.text() call can fail if the user hangs up the connection before the body is fully received. Make sure to handle this case. This can happen in all methods that read from the request body, such as req.json(), req.formData(), req.arrayBuffer(), req.body.getReader().read(), req.body.pipeTo(), etc. 3. Check your routes: The documentation provides examples of how to handle routes and form submissions. Make sure your routes are set up correctly and that you're handling form submissions properly. 4. Debugging: If you're still having issues, try to isolate the problem. Can you log the JSON data before you parse it? Does the error still occur if you hard-code some JSON data instead of getting it from the request? Remember, these are general suggestions and may not directly solve your issue. If you're still having trouble, you might want to ask for help in the Deno community or on Stack Overflow. 🦕
IioB10/6/2023
You're not allowed to send a request to youself in Deno Deploy. Call the function directly!
EEGamalielGZ10/6/2023
Why I'm not allowed when the platform gives you the possibility to deploy REST APIs, and also I can do HTTP Request locally with problem from the proyect running locally on requesting with Postman? I don't get it 😵‍💫
Ccknight10/6/2023
It's at least partly for protection of the Deploy infra to avoid applications getting into infinite loops where they call themselves, which call themselves, which call themselves, which...
IioB10/6/2023
It's mostly ^ but there's also a performance thing, why go through the network! You're on the server regardless!
EEGamalielGZ10/6/2023
So, in the case I want to fetch my own API how can I do it?
IioB10/6/2023
Just... run the code the api runs?
// /api/whatever.ts
export function getResponse() {
return new Response("hello world");
}

function handler(req: Request) {
return getResponse();
}

// /api/another.ts
import { getResponse } from "./whatever.ts";

function handler(req: Request) {
const res = getResponse();
// some more logic
}
// /api/whatever.ts
export function getResponse() {
return new Response("hello world");
}

function handler(req: Request) {
return getResponse();
}

// /api/another.ts
import { getResponse } from "./whatever.ts";

function handler(req: Request) {
const res = getResponse();
// some more logic
}
EEGamalielGZ10/6/2023
Ok, so I am supossed to divide the logic from the api from the Handler so then I'll be able to consume it? Kida weird, but it might work, thanks. If i have doubts I'll ask
IioB10/6/2023
yup 👍
EEGamalielGZ10/6/2023
Also,I forgot to include somethin' on what i said. This error only happens when I do POST query

Looking for more? Join the community!

Recommended Posts
Deno Deploy - is it possible to have 2 servers running?Maybe Im using it completely wrong, but locally when i develop I have two Deno servers running: BacNPM package randomly brokeI've been using the imagekit package for my fresh project, and it's been working fine since I instalsubpackage imports with npm specifierse.g. `import colors from "npm:tailwindcss/colors"` currently fails, is this not supposed to work? SIs it possible to use Cache-Control headers to control Deno's cacheI've seen via an issue ( https://github.com/denoland/deno/issues/16296 ) that Deno stores its metadaDeno Deploy Queue trouble in productionI'm encountering an issue with Deno Queue in my Deno Deploy project, and I'm hoping to get some guidDeno compile target errorHello, I am trying to compile a Deno api using `deno --unstable ./path/to/api/index.ts --output ./paHow to avoid the method POST to executed in the URL I am redirected to?How to avoid the method POST to executed in the URL I am redirected to? routes/admin/login.tsx ```thow to use Untar without deprecated functions?`Untar` from std/archives requires an instance of `Reader` - apparently most functions return some RHelp, does the middleware example in the Deno Fresh documentation not work for anyone else?I tried to follow the example in Deno Fresh about middlewares, but it doesn't work, the content `ctxDeno Cache locationHello, I am trying to cache my dependencies during the compile action using Github Actions, where doHow to build rusty_v8 with old v8 version?Hello all ! I am trying to build rusty_v8 (https://github.com/denoland/rusty_v8) with an old versionCan someone explain WebSocketStream to me?Whenever I try to connect using WebSocketStream and the host doesn't respond, my program inevitably deno doc: error: fp-tsthat's pretty much all I have :/ Running `deno doc Server.ts` only yields `error: fp-ts`. Can I enabI want to add my package xmlbuilder2 to deno.landBut somebody already added it, albeit with his own forked repository (now non-existent, thus unusablCache imports in deno.jsonIs there a way to cache imports defined in deno.json? I am hoping to avoid additional deps.ts file.typescript type definition for deno.jsonDoes it exist, and where can I get it?Publishing (and configuring) the webhook for deno.land from monorepoThanks in advance for your help! I went through the setup on https://deno.com/add_module for my jupLooking for a Dev who is well-versed in Fast-Delivery of building front-end pages using React.js forLooking for a Dev who is well-versed in Fast-Delivery of building front-end pages using React.js forHow to assert object with a field of a given type?Hi, I'm writing an integration test that needs to assert an object response, where the ID field can Deno + LitHey how can use the [Lit](https://lit.dev/) framework with Deno? Is there a guide or config on how t