halostatue

halostatue

Phoenix Error Rendering & Multiple Endpoints

These are both likely a case of either “holding the tool wrong” or “using the wrong tool”, but I am looking for information and advice.

We have built our Phoenix app in such a way that we have, excepting for ErrorView, never used a view (we are an API-only setup, and use GraphQL as our primary API, but have integrations and other needs where we have some non-GraphQL (mostly JSON) APIs. There are very few “resources”. Our controller methods (often not called by the traditional names because they aren’t resources) mostly use Phoenix.Controller.json/2 directly for rendering.

Question 1

Is there a way to handle errors directly in a Phoenix application without defining render_errors[view: …] (up to 1.6) or render_errors[formats: …] (1.7+)?

Question 2

I believe that we have been also doing things wrong with how we handle certain sub-applications (we use an umbrella).

Our app structure looks something like this:

  • MyApp
  • clients:
    • MyApp.Client1
    • MyApp.Client2
  • MyApp.GraphQL
  • MyApp.Web

MyApp.Web has defined an endpoint, and it defines forward routes (excessively simplified here):

forward "/graphql", MyApp.GraphQL
forward "/clients/one", MyApp.Client1.Router
forward "/clients/two", MyApp.Client2.Router
# ...

As of right now, each client (MyApp.Client1, MyApp.Client2, etc.) defines another Phoenix.Endpoint for testing (but not for non-test mode). Is there a good reason to define such an Endpoint, or is there a way to avoid defining such an Endpoint as it is not used in the normal implementation?

We can’t reference MyApp.Web.Endpoint from MyApp.Client1 (etc.) without getting a cross-reference issue (access is always up in the list; client apps have no knowledge of one another, etc.).

Most Liked Responses

LostKobrakai

LostKobrakai

What’s the reason for trying to avoid them? You’ll always have errors that you cannot handle explicitly. E.g. a 500 is almost by definition an error you didn’t handle. Your remarks make it sound like views are something to be avoided, which isn’t the case.

You could use a test endpoint, where you forward requests at runtime to different routers based on some information in the conn, which you setup in tests.

Where Next?

Popular in Questions Top

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
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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

Other popular topics Top

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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XXX...
New

We're in Beta

About us Mission Statement