my-flow / fintex

Elixir-based client library for HBCI 2.2 and FinTS 3.0
Other
27 stars 17 forks source link

Use Fintex from within a Phonix app #2

Closed stayhero closed 8 years ago

stayhero commented 8 years ago

Hi.

I'm not really familiar with Elixir yet, hence this is most likely not a fintex issue but rather a rookie mistake I'm making.

I wanted to use fintex from within a Phoenix application. I added fintex to mix.exs (as dependency and as an application): https://github.com/stayhero/fintex-sample-phoenix

However... starting the phoenix app, I get weird errors when trying to use fintex:

 iex -S mix phoenix.server
use FinTex; bank = %{blz: "30150200", url: "https://banking-rl2.s-fints-pt-rl.de/fints30", version: "300"}; creds = %{login: "testtesttest", pin: "11111"}; f = FinTex.new(bank, creds)

I get this:

** (FinTex.Error) {:error, {:badmatch, {:error, {%HTTPotion.HTTPError{message: "{:EXIT, {{:function_clause, [{:gen, :call, [#PID<0.437.0>, :\"$gen_call\", {:send_req, {{:url, 'https://banking-rl2.s-fints-pt-rl.de/fints30', 'banking-rl2.s-fints-pt-rl.de', 443, :undefined, :undefined, '/fints30', :https, :hostname}, [{'Content-Type', 'text/plain'}, {'Connection', 'keep-alive'}], :post, \"SE5IQks6MTozKzAwMDAwMDAwMDM4MSszMDArMCsxJ0hOVlNLOjk5ODozK1BJTjoxKzk5OCsxKzE6OjArMToyMDE2MDMyMDoxODM2MTMrMjoyOjEzOkA4QAAAAAAAAAAAOjU6MSsyODA6MzAxNTAyMDA6dGVzdHRlc3R0ZXN0OlY6MDowKzAnSE5WU0Q6OTk5OjErQDIxNkBITlNISzoyOjQrUElOOjErOTk5K0ZpblRleCsxKzErMTo6MCs0NDM1ODQ2MSsxOjIwMTYwMzIwOjE4MzYxMysxOjk5OToxKzY6MTA6MTYrMjgwOjMwMTUwMjAwOnRlc3R0ZXN0dGVzdDpTOjA6MCdIS0lETjozOjIrMjgwOjMwMTUwMjAwK3Rlc3R0ZXN0dGVzdCswKzEnSEtWVkI6NDozKzArMCsxK0ZpblRleCswLjIuMCdIS1NZTjo1OjMrMCdITlNIQTo2OjIrRmluVGV4KysxMTExMScnSE5IQlM6NzoxKzEn\", [stream_to: #PID<0.436.0>, ssl_options: []], nil}}, nil], [file: 'gen.erl', line: 149]}, {:gen_server, :call, 3, [file: 'gen_server.erl', line: 208]}, {:ibrowse_http_client, :send_req, 7, [file: 'src/ibrowse_http_client.erl', line: 112]}, {:ibrowse, :do_send_req, 7, [file: 'src/ibrowse.erl', line: 474]}, {:ibrowse, :try_routing_request, 14, [file: 'src/ibrowse.erl', line: 366]}, {HTTPotion, :request, 3, [file: 'lib/httpotion.ex', line: 209]}, {FinTex.Connection.HTTPClient, :send_request, 3, [file: 'lib/connection/http_client.ex', line: 55]}, {FinTex.Connection.HTTPClient, :init, 1, [file: 'lib/connection/http_client.ex', line: 17]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 328]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}, {:gen_server, :call, [#PID<0.437.0>, {:send_req, {{:url, 'https://banking-rl2.s-fints-pt-rl.de/fints30', 'banking-rl2.s-fints-pt-rl.de', 443, :undefined, :undefined, '/fints30', :https, :hostname}, [{'Content-Type', 'text/plain'}, {'Connection', 'keep-alive'}], :post, \"SE5IQks6MTozKzAwMDAwMDAwMDM4MSszMDArMCsxJ0hOVlNLOjk5ODozK1BJTjoxKzk5OCsxKzE6OjArMToyMDE2MDMyMDoxODM2MTMrMjoyOjEzOkA4QAAAAAAAAAAAOjU6MSsyODA6MzAxNTAyMDA6dGVzdHRlc3R0ZXN0OlY6MDowKzAnSE5WU0Q6OTk5OjErQDIxNkBITlNISzoyOjQrUElOOjErOTk5K0ZpblRleCsxKzErMTo6MCs0NDM1ODQ2MSsxOjIwMTYwMzIwOjE4MzYxMysxOjk5OToxKzY6MTA6MTYrMjgwOjMwMTUwMjAwOnRlc3R0ZXN0dGVzdDpTOjA6MCdIS0lETjozOjIrMjgwOjMwMTUwMjAwK3Rlc3R0ZXN0dGVzdCswKzEnSEtWVkI6NDozKzArMCsxK0ZpblRleCswLjIuMCdIS1NZTjo1OjMrMCdITlNIQTo2OjIrRmluVGV4KysxMTExMScnSE5IQlM6NzoxKzEn\", [stream_to: #PID<0.436.0>, ssl_options: []], nil}}, nil]}}}"}, [{HTTPotion, :handle_response, 1, [file: 'lib/httpotion.ex', line: 209]}, {FinTex.Connection.HTTPClient, :send_request, 3, [file: 'lib/connection/http_client.ex', line: 55]}, {FinTex.Connection.HTTPClient, :init, 1, [file: 'lib/connection/http_client.ex', line: 17]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 328]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}}}
    (fintex) lib/command/sequencer.ex:83: FinTex.Command.Sequencer.call_http/3
    (fintex) lib/command/initialize.ex:34: FinTex.Command.Initialize.initialize_dialog/3
    (fintex) lib/fintex.ex:66: FinTex.new/3

Am I doing something stupid here? If I had to guess I would bet on a problem with ibrowse or some too old/new dependencies introduced by Phoenix?

stayhero commented 8 years ago

Ok, got it. The issue was caused by a missing timeout config in the Phoenix app.

config/config.exs:

config :fintex, :http_options, [ timeout: 10_000 ]

Probably it makes sense to support a default timeout value? Or throw a nicer error message? I created a very basic pull request #3, feel free to throw it away if you don't like it. :-)