Skip to content
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

Merged
merged 2 commits into from
Nov 29, 2024
Merged

Handle exceptions in ModelController #1704

merged 2 commits into from
Nov 29, 2024

Conversation

jmthomas
Copy link
Member

@jmthomas jmthomas commented Nov 13, 2024

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.

@jmthomas jmthomas requested a review from ryanmelt November 13, 2024 02:20
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Project coverage is 76.30%. Comparing base (be0a654) to head (abef5c0).
Report is 46 commits behind head on main.

Files with missing lines Patch % Lines
...os-cmd-tlm-api/app/controllers/model_controller.rb 0.00% 8 Missing ⚠️
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              
Flag Coverage Δ
python 83.96% <ø> (-0.03%) ⬇️
ruby-api 48.61% <0.00%> (-0.09%) ⬇️
ruby-backend 82.14% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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.

@ryanmelt ryanmelt merged commit 368af4b into main Nov 29, 2024
26 of 27 checks passed
@ryanmelt ryanmelt deleted the tools branch November 29, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants