MediaProxy error for unknown status codes
Seems like when the MediaProxy fails, it attempts to translate the status code into a string for logs. When the status code is not an RFC status code, it results in an error:
Jul 27 10:25:54 frontend.poa.st mix[2046241]: Server: phoenix:80 (http)
Jul 27 10:25:54 frontend.poa.st mix[2046241]: Request: GET /proxy/abcd/efg/hijk.jpg
Jul 27 10:25:54 frontend.poa.st mix[2046241]: ** (exit) an exception was raised:
Jul 27 10:25:54 frontend.poa.st mix[2046241]: ** (ArgumentError) unknown status code 523
Jul 27 10:25:54 frontend.poa.st mix[2046241]: Custom codes can be defined in the configuration for the :plug application,
Jul 27 10:25:54 frontend.poa.st mix[2046241]: under the :statuses key (which contains a map of status codes as keys and
Jul 27 10:25:54 frontend.poa.st mix[2046241]: reason phrases as values). For example:
Jul 27 10:25:54 frontend.poa.st mix[2046241]: config :plug, :statuses, %{998 => "Not An RFC Status Code"}
Jul 27 10:25:54 frontend.poa.st mix[2046241]: After defining the config for custom statuses, Plug must be recompiled for
Jul 27 10:25:54 frontend.poa.st mix[2046241]: the changes to take place using:
Jul 27 10:25:54 frontend.poa.st mix[2046241]: MIX_ENV=dev mix deps.clean plug --build
Jul 27 10:25:54 frontend.poa.st mix[2046241]: Doing this will allow the use of the integer status code 998 as
Jul 27 10:25:54 frontend.poa.st mix[2046241]: well as the atom :unavailable_for_legal_reasons in many Plug functions.
Jul 27 10:25:54 frontend.poa.st mix[2046241]: For example:
Jul 27 10:25:54 frontend.poa.st mix[2046241]: put_status(conn, :not_an_rfc_status_code)
I'm seeing errors for 523 and 526, mostly 523. These come from Cloudflare: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#523
I'm not sure the best way to handle this. We could catch the call to Plug.Conn.Status.reason_phrase/1
and return "unknown error". Or we could add Cloudflare status codes to the Plug config.
EDIT: In Soapbox I just added Cloudflare status codes to the config: https://gitlab.com/soapbox-pub/soapbox/-/merge_requests/47/diffs
Edited by Alex Gleason