question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Great work with this module!

There is one thing missing, though: I would like to have dynamic messages for my errors when possible. To make that happen, message option could be received as function.

As you don’t expose ApolloError, things are harder they it should to increment your lib. Here is a work around I’m using to achieve it:

const createDynamicError = (name, opts = {}) => class CustomError {
  constructor (...args) {
    const config = typeof opts === 'string' || typeof opts === 'function'
      ? { message: opts }
      : opts

    if (typeof config.message === 'function') {
      config.message = config.message(...args)
    }

    return new (createError(name, config))(...args.slice(-1))
  }
}

You could then use it like so:

const UserNotFoundError = createCustomError('UserNotFoundError', {
  message: username => `User ${username} not found`
})

// Or, shurtcuted:
const UserNotFoundError = createCustomError('UserNotFoundError', username => `User ${username} not found`)

// And use it like that:
new UserNotFoundError('lucas')

// Or, with data as in the original createError:
new UserNotFoundError('lucas', { data: { foo: 'bar' } })

Hope it helps someone 😉

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thebigredgeekcommented, Apr 28, 2017

I’m closing this for now, since there doesn’t seem to be any interest in moving forward

0reactions
thebigredgeekcommented, Apr 26, 2017

@scf4 I mostly agree, but I also don’t feel overly pained about adding this if enough people want it. I personally render the messages directly in the client, because my current app doesn’t have to worry about i18n etc. That said, there is nothing stopping anyone from using a factory function to return errors with dynamic messages without baking any new functionality into the lib.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Messaging for eCommerce: Getting Started and ...
In other words, Dynamic Messages act as triggers that drive purchase behavior with visual cues that give customers more information about ...
Read more >
The impact and importance of dynamic messaging - SMSGlobal
Dynamic SMS messaging allows you to send each customer personalised content with different images or links based on their expressed preferences ...
Read more >
7 Dynamic Messages that Leverage Consumer Psychology for ...
Dynamic messages are “dynamic” because they auto-optimize based on the data of the customer. In other words, they use AI to test messages...
Read more >
Dynamic Messaging for DNA - Fiserv
Expand relationships while enhancing service by using Dynamic Messaging for DNA from Fiserv to deliver real-time messages to your front-line staff.
Read more >
Dynamic Messages - Gupshup
Dynamic messages are messages whose contents can be changed programmatically. The bot messages in the scripting tool are really templates. You can create ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found