Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Proposal] Allow error property regex matching #15

Open
4 tasks
craigmichaelmartin opened this issue Jul 20, 2021 · 0 comments
Open
4 tasks

[Feature Proposal] Allow error property regex matching #15

craigmichaelmartin opened this issue Jul 20, 2021 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@craigmichaelmartin
Copy link
Owner

craigmichaelmartin commented Jul 20, 2021

Many times errors from 3rd parties are just of type Error and have to be inspected. What if we supported error property regex/string-matching? Thus:

In addition to:

const [data, duplicateError] = await fa(create(/*...*/), DuplicateError)

we would support

const [data, duplicateError] = await fa(create(/*...*/), {message: /^duplicate key/})

Which would match for this error:

Error {
    "name": "error",
    "length": 221,
    "severity": "ERROR",
    "code": "23505",
    "detail": "Key (line_item_id)=(12345) already exists.",
    "schema": "public",
    "table": "review",
    "constraint": "review_line_item_id_key",
    "message": "duplicate key value violates unique constraint \"review_line_item_id_key\""
}

This would also work

const [data, duplicateError] = await fa(create(/*...*/), {constraint: 'review_line_item_id_key'})

This regex/string matching of error property should also work for N-levels. If the error was of type DuplicateError, these would be equivalent:

const [data, duplicateError] = await fa(create(/*...*/), DuplicateError)
const [data, duplicateError] = await fa(create(/*...*/), {constructor: {name: 'DuplicateError'}})

This would also be supported in the alternate API of allowing the errors to be in an array.


Requirements:

  • Property matching of error by regex or string
  • Property matching supports N-levels deep of matching
  • This is supported in the alternate API
  • Tests for all of these things
@craigmichaelmartin craigmichaelmartin added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant