-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle exceptions in ModelController #1704
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1704 +/- ##
==========================================
- Coverage 76.32% 76.30% -0.02%
==========================================
Files 603 602 -1
Lines 46096 46126 +30
Branches 837 837
==========================================
+ Hits 35183 35197 +14
- Misses 10817 10833 +16
Partials 96 96
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -26,6 +26,9 @@ class ModelController < ApplicationController | |||
def index | |||
return unless authorization('system') | |||
render json: @model_class.names(scope: params[:scope]) | |||
rescue StandardError => error | |||
render json: { status: 'error', message: error.message }, status: 500 | |||
OpenC3::Logger.error(error.formatted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger errors cause messages in CmdTlmServer - Probably don't want that here. Change to using rails logger.
@@ -39,6 +42,9 @@ def create(update_model = false) | |||
OpenC3::Logger.info("#{@model_class.name} created: #{params[:json]}", scope: params[:scope], user: username()) | |||
end | |||
head :ok | |||
rescue StandardError => error | |||
render json: { status: 'error', message: error.message }, status: 500 | |||
OpenC3::Logger.error(error.formatted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger errors cause messages in CmdTlmServer - Probably don't want that here. Change to using rails logger.
@@ -48,6 +54,9 @@ def show | |||
else | |||
render json: @model_class.get(name: params[:id], scope: params[:scope]) | |||
end | |||
rescue StandardError => error | |||
render json: { status: 'error', message: error.message }, status: 500 | |||
OpenC3::Logger.error(error.formatted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger errors cause messages in CmdTlmServer - Probably don't want that here. Change to using rails logger.
@@ -59,5 +68,8 @@ def destroy | |||
@model_class.new(name: params[:id], scope: params[:scope]).destroy | |||
OpenC3::Logger.info("#{@model_class.name} destroyed: #{params[:id]}", scope: params[:scope], user: username()) | |||
head :ok | |||
rescue StandardError => error | |||
render json: { status: 'error', message: error.message }, status: 500 | |||
OpenC3::Logger.error(error.formatted) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger errors cause messages in CmdTlmServer - Probably don't want that here. Change to using rails logger.
|
Also handle bad URLs in ToolsTab and AppNav.
Any exception raised in a model.rb and not explicitly handled will just result in a 500 error. I recently made a change to
tool_model.rb
in #1701 that checks the URL and raises if it is bad. This just resulted in an unknown 500 error before the change but now shows a popup with the error message.