mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-02-10 16:07:10 +00:00
Add backtraces to errors (#1498)
Error handling has been reworked to always go through the new `error_template`, `error_json` and `error_atom` macros. They all accept a status code followed by a string message or an exception object. `error_json` accepts a hash with additional fields as third argument. If the second argument is an exception a backtrace will be printed, if it is a string only the string is printed. Since up till now only the exception message was printed a new `InfoException` class was added for situations where no backtrace is intended but a string cannot be used. `error_template` with a string message automatically localizes the message. Missing error translations have been collected in https://github.com/iv-org/invidious/issues/1497 `error_json` with a string message does not localize the message. This is the same as previous behavior. If translations are desired for `error_json` they can be added easily but those error messages have not been collected yet. Uncaught exceptions previously only printed a generic message ("Looks like you've found a bug in Invidious. [...]"). They still print that message but now also include a backtrace.
This commit is contained in:
@@ -12,9 +12,7 @@ class Invidious::Routes::Watch < Invidious::Routes::BaseRoute
|
||||
id = env.params.query["v"]
|
||||
|
||||
if env.params.query["v"].empty?
|
||||
error_message = "Invalid parameters."
|
||||
env.response.status_code = 400
|
||||
return templated "error"
|
||||
return error_template(400, "Invalid parameters.")
|
||||
end
|
||||
|
||||
if id.size > 11
|
||||
@@ -56,10 +54,8 @@ class Invidious::Routes::Watch < Invidious::Routes::BaseRoute
|
||||
rescue ex : VideoRedirect
|
||||
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
||||
rescue ex
|
||||
error_message = ex.message
|
||||
env.response.status_code = 500
|
||||
logger.puts("#{id} : #{ex.message}")
|
||||
return templated "error"
|
||||
return error_template(500, ex)
|
||||
end
|
||||
|
||||
if preferences.annotations_subscribed &&
|
||||
|
||||
Reference in New Issue
Block a user