benonymus

benonymus

Different error on dev and production

Hey there,
When I upload a file that is too big, in dev I am getting the phoenix error that looks like this:

Plug.Parsers.RequestTooLargeError at POST/topics/4gvJMZkdbBpN0e65/post_attachment

the request is too large. If you are willing to process larger requests, please give a :length to Plug.Parsers

and has a status of: 413 Request Entity Too Large

but when I deploy the app this error gets swallowed it seems, and just an empty 500 is returned.
in the AWS logs I can see the 413.

How to handle this error to have the same error the same way on both environments?

Most Liked

axelson

axelson

Scenic Core Team

Hmmm, I wonder if that error message could be improved to guide users to the correct fix for their needs. At the very least I believe we can say that when only html is specified in render_errors that only an iolist or binary are valid inputs and other inputs should result in an error message.

OvermindDL1

OvermindDL1

Not the view name but rather what ‘higher up’ in the callstack is calling your render function. In a base error rendrerer there’s very little above it and I’m not sure if the content-type requested by the client is followed or not (since it’s an error and the body shouldn’t be used for data anyway).

You can always return the stacktrace in that function and see what it’s going through, there might be an option? :slight_smile:

Edit: Googled a bit and the Phoenix View documentation shows rendering JSON from a map in an example. So it should work.

That’s for rendering from controllers, not errors though, I’m unsure about error handling.

jola

jola

I’m curious what the content-type is of the response then.

@OvermindDL1 as far as I can tell, the error view is set as a config option on the endpoint (render_errors) where you can specify a list of content types. Generating a fresh phoenix app with no HTML gives you an error view that has this comment

  # If you want to customize a particular status code
  # for a certain format, you may uncomment below.
  # def render("500.json", _assigns) do
  #   %{errors: %{detail: "Internal Server Error"}}
  # end

so I see no reason why returning maps wouldn’t work here either.

In fact, @benonymus, I’m curious what your render_errors config option looks like in config/config.exs, config/dev.exs and config/prod.exs. Maybe you’ve put JSON in one and HTML in another? It should look something like this

render_errors: [view: HelloWeb.ErrorView, accepts: ~w(json)],

Last Post!

pystar

pystar

I was able to discover a solution on StackOverflow which seems to solve the problem of the OP.

6

In your MyAppWeb.Endpoint file you should have something like this to configure the parser:

plug Plug.Parsers,
  parsers: [:urlencoded, :multipart, :json],
  pass: ["*/*"],
  json_decoder: Poison
Change parsers to:

  parsers: [:urlencoded, 
           {:multipart, length: 20_000_000},
            :json]
  query_string_length: 1_000_000,

https://stackoverflow.com/questions/49230116/413-request-entity-too-large-elixir-plug

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
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

We're in Beta

About us Mission Statement