For file sanity checks that is being uploaded to phoenix ,
- To validate mime, filename,etc
- we get a Plug.Upload after being parsed by Plug.Parser, in actions.
- but to put file size limit , Plug.Parsers are used.
- in router
- or in endpoint
But if file is large than given certain threshold, it raises.
exceptions.
defmodule RequestTooLargeError do
@moduledoc """
Error raised when the request is too large.
"""
defexception message:
"the request is too large. If you are willing to process " <>
"larger requests, please give a :length to Plug.Parsers",
plug_status: 413
end
how do i show info to the user, that what happened?. Instead of internal server error
defmodule RTValues do
@moduledoc false
def size_limit(), do: Application.get_env(:core, :size_limit)
def parser_options(),i
do: [
parsers: [
:urlencoded,
{:multipart, length: size_limit()},
:json
],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
]
end
defmodule Web.Router do
pipeline :browser do
plug Plug.Parsers,RTValues.parser_options()
.
.
.
end
.
.
.
end
how do i show info to the user, that what happened?. Instead of internal server error
what am i doing wrong?
SAME GOES FOR API ONLY ENDPOINT HANDLING