https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • j

    James

    05/27/2023, 7:18 PM
    Or just
    if(!proto_res?.properties?.periods)
    with optional chaining
  • j

    James

    05/27/2023, 7:19 PM
    are you 100% certain that API is perfect and only ever returns JSON when asked? 😅 When working with external APIs, it's always better to add resilience by checking what's actually returned
  • k

    kian

    05/27/2023, 7:19 PM
    Nope
  • i

    IdkWhatever69

    05/27/2023, 7:19 PM
    true true; i'll do that
  • k

    kian

    05/27/2023, 7:19 PM
    Oh no, it is
  • k

    kian

    05/27/2023, 7:19 PM
    It's the very last inheritable property
  • f

    F0rce

    05/27/2023, 7:19 PM
    perfect. thanks a lot 🙂
  • i

    IdkWhatever69

    05/27/2023, 7:20 PM
    if .properties dont exist shouldn't .properties.periods be undefined? and if it is, i do check that
    Copy code
    ts
    export function exists<T>(data: T|null|undefined): data is T {
      if (
          (data === null) ||
          (data === undefined)
      ) return false;
      return true;
    }
  • j

    James

    05/27/2023, 7:22 PM
    .properties.periods
    would throw a
    TypeError
    if
    properties
    doesn't exist. For example:
    Copy code
    js
    const obj = {foo: 'bar'}
    console.log(obj.foo) // bar
    console.log(obj.bar) // undefined
    console.log(obj.bar.baz) // TypeError
  • a

    AA

    05/27/2023, 7:23 PM
    I want to create a single git repo, with lots of workers (mostly webhooks, so stripe/ses/etc) this seems smarter than 1 big project since i can update/change them 1 at a time.. anyone have a good example of how to structure this? just 1 directory per worker, with its own wrangler? or?
  • i

    IdkWhatever69

    05/27/2023, 7:24 PM
    right right 😅

    https://cdn.discordapp.com/attachments/779390076219686943/1112098934026932244/Screenshot_2023-05-28_at_12.53.54_AM.pngâ–¾

  • s

    silence

    05/27/2023, 7:25 PM
    (error) Error: Unexpected Server Error
    lol I sure wish this error was better
  • a

    andrew.rfc

    05/27/2023, 7:52 PM
    since
    performance.now()
    isn’t available in Workers and
    Date.now()
    doesn’t increment unless you do I/O is there any way to actually benchmark CPU bound function execution times in a worker?
  • k

    kian

    05/27/2023, 7:58 PM
    Nope
  • k

    kian

    05/27/2023, 7:58 PM
    performance.now()
    is available but it just calls
    Date.now()
  • a

    andrew.rfc

    05/27/2023, 8:06 PM
    That’s annoying. Other platforms mitigate timing attacks but just skewing the resolution, but outright disabling it is an approach i guess
  • a

    AA

    05/27/2023, 8:08 PM
    wrangler tail <-- all i get are OKs even tho I'm generating
    internal server error
    anyplace to look to see better logging?
  • a

    AA

    05/27/2023, 8:08 PM
    maybe this is a wrangler question..
  • w

    Walshy | Pages

    05/27/2023, 8:09 PM
    what do you mean you're generating it?
  • w

    Walshy | Pages

    05/27/2023, 8:09 PM
    are you catching the exception?
  • a

    AA

    05/27/2023, 8:10 PM
    not naturally. only if hono is
  • a

    AA

    05/27/2023, 8:10 PM
    Copy code
    ts
    import { Hono } from 'hono'
    import { Client } from 'pg'
    
    const app = new Hono()
    
    const connstring = "postgresql://postgres@localhost:5432/hhscdev?schema=public"
    
    app.get('*', async (c) => {
      const client = new Client("postgresql://postgres@localhost:5432/hhscdev?schema=public");
      await client.connect();
      
      const { rows: [{ now }] } = await client.query('select now();');
      return c.text(`Hello Hono! ${now}`)
    })
    
    export default app
  • w

    Walshy | Pages

    05/27/2023, 8:11 PM
    yeah Hono does it's own catching of unknown errors
  • w

    Walshy | Pages

    05/27/2023, 8:11 PM
    So that's why it's ok, the error is being handled
  • w

    Walshy | Pages

    05/27/2023, 8:11 PM
    you can do
    app.onError
    to add your own handler
  • a

    AA

    05/27/2023, 8:11 PM
    ah, just using that because its recommended. wonder if i should abandon it. or find a way to dump the error
  • a

    AA

    05/27/2023, 8:12 PM
    really just using a single 'url' per project, so maybe hono is overkill
  • a

    AA

    05/27/2023, 8:20 PM
    @Walshy | Pages thanks. 1 problem down. 99 more to go 🙂
  • a

    AA

    05/27/2023, 8:23 PM
    ooh, another minor quirk. i'm doing a wrangler --env staging.. but in the workers dashboard it says the environment is 'production' are these things not linked?
  • a

    AA

    05/27/2023, 8:23 PM
    also did a vars = { ENVIRONMENT = "staging" }
1...25052506250725082509Latest