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

Allow config/2 to send errors in spec compliant format #1341

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

bryanjos
Copy link
Contributor

Related to #1340

This PR makes it so that if config/2 returns an error tuple where the second element is a map, then that map is treated as the error response.

Subscription config errors currently expect a tuple of {:error, msg }. If message is an map, when returned to the user, it looks like:

"errors": [
    {"message": {"extensions": {"code": "BAD_REQUEST"}, "message": "Invalid argument"}}
]

This causes trouble for us as we return spec compliant errors and they get wrapped in the message.

This PR makes it so returning the following from config/2

{:error, %{message: "Invalid argument", extensions: %{code: "BAD_REQUEST"}}

Will return

"errors": [
    {"extensions": {"code": "BAD_REQUEST"}, "message": "Invalid argument"}
]

Copy link
Contributor

@michaelcaterisano michaelcaterisano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me!

@benwilson512
Copy link
Contributor

I'm perfectly happy to let ya'll decide and move forward on this. I would recommend adding a test case after this to absinthe_phoenix to make sure this actually works end to end.

@bryanjos
Copy link
Contributor Author

bryanjos commented Oct 2, 2024

I wrote a test case for absinthe_phoenix locally and verified everything passes. I can make a PR there

@bryanjos bryanjos changed the title Treat maps returned from config/2 as response Allow config/2 to send errors in spec compliant format Oct 2, 2024
@bryanjos bryanjos merged commit a093119 into main Oct 2, 2024
15 checks passed
@bryanjos bryanjos deleted the bryanj/config_error_return_maps branch October 2, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants