ngw

ngw

Error handling with Tesla

Hi, I’m using Tesla for a fun project, and I noticed it “explodes” instead of, for example, returning an {:error, something} tuple in case something goes wrong.

iex(2)> Tesla.get("http://foobar.baz")
** (Tesla.Error) adapter error: :econnrefused
    lib/tesla/middleware/core.ex:10: Tesla.Middleware.Normalize.normalize/1

How to handle this? Should I use a try block? What if the Tesla call is inside an Enum.map over many urls? Is there an idiomatic way to handle this?

Most Liked

teamon

teamon

This has been brought up in the past and just now - please take a look at More conventional output · Issue #64 · elixir-tesla/tesla · GitHub and Return error tuple instead of raising errors by gdub01 · Pull Request #81 · elixir-tesla/tesla · GitHub
As you can see, it is very easy to change this behaviour to whatever suits you best - tesla was designed to be extensible as much as possible. I’m happy to continue the discussion in tesla’ github issues.

I should’ve probably ignore this, but as a active member of elixir community I feel obligated to do my best to make it a nice and helpful place for everyone and stand up to undesired behaviour.

I know having issues with 3rd party libraries can be frustrating. But please remember that most of the time these libraries are made by people for free, with their own free time. Pointing that something “should” be done this way or another is not a good way to start a discussion. Not to mention the rest of pointless, ranting comments here. This is the perfect example of making a hostile community.

Thank you @vmoravec for a reasonable approach to this issue. That’s how we can get nice things.

12
Post #6
NobbZ

NobbZ

The documentation doesn’t even mention to throw or raise, and as far as I was able to scan the docs, there is no tupled version of the functions available.

In my opinion the API should be reworked drastically! Catching is expensive, and not everyone wants to just crash…

ngw

ngw

Yeah I guess it’s a bit odd, might be the case to switch to another more “educate” library like HTTPipe, because honestly it doesn’t seem such an incredible occurrence to try to GET a url that doesn’t exist for an HTTP library :slight_smile:

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement