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 https://github.com/teamon/tesla/issues/64 and https://github.com/teamon/tesla/pull/81
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:

vmoravec

vmoravec

Before switching to any other library I would recommend to raise an issue on Tesla github repo and ask the maintainer of the library for improvement or for reasoning why it was designed that way: https://github.com/teamon/tesla

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
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

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement