Dynamic messages
See original GitHub issueGreat 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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m closing this for now, since there doesn’t seem to be any interest in moving forward
@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.