Skip to content

avoiding the use of the StandardError exception #331

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -337,6 +337,44 @@ render status: :forbidden
...
----

=== Error Message [[http-status-code-symbols]]

It is recommended to avoid using the StandardError exception when rendering error messages in the code, as this may capture an unintended and controlled error.
Instead, it is suggested to capture specific errors or send a customized standard error message.
This ensures more accurate and effective exception handling in the program.

[source,ruby]
----
# bad
...
rescue StandardError => e
render json: {error_msg: e.message}
end
...
# bad - usign in flash message
...
rescue StandardError => e
flash[:error] = e.message
end
...
# good
...
rescue StandardError => e
render json: {error_msg: 'Error in the application'}
end
...
# good
...
rescue ParticularError => e
render json: {error_msg: e.message}
end
...
----

== Models

=== Model Classes [[model-classes]]