Skip to content

how to remove too much map_error ? #2765

Discussion options

You must be logged in to vote

You could use one decoder instead of doing it in steps:

response.body
|> json.decode(dynamic.field("json", of: dynamic.string)
|> result.map_error(fn(e) { hackney.Other(dynamic.from(e)) })

You could also make your error type more precise by not using Dynamic. This would make it more concise and also easier to work with. It's very rare that you should have a Dynamic from anywhere but user input.

response.body
|> json.decode(dynamic.field("json", of: dynamic.string)
|> result.map_error(JsonError)

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lost22git
Comment options

@lpil
Comment options

Answer selected by lost22git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants