Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class Exceptions < Application
  2. skip_before :parse_supplied_sscj1
  3. skip_before :ensure_authenticated
  4.  
  5. provides :sscj1
  6.  
  7. # ...
  8.  
  9. # handle RecordInvalid exceptions (406)
  10. def record_invalid
  11. @errors = request.exceptions.first.errors
  12. rename_error_fields!
  13. render
  14. end
  15.  
  16. # handle client errors
  17. def client_error
  18. # Re-Raise so we get the pretty merb error document instead.
  19. raise request.exceptions.first if content_type == :html
  20.  
  21. @exceptions = request.exceptions
  22. @show_details = Merb::Config[:exception_details]
  23.  
  24. # Leave the :standard_error part, so that the other actions that call
  25. # this know what template to render
  26. render :client_error
  27. end
  28.  
  29. # Everything else (500)
  30. def standard_error
  31. # Re-Raise so we get the pretty merb error document instead.
  32. raise request.exceptions.first if content_type == :html
  33.  
  34. @exceptions = request.exceptions
  35. @show_details = Merb::Config[:exception_details]
  36.  
  37. # Leave the :standard_error part, so that the other actions that call
  38. # this know what template to render
  39. render :standard_error
  40. end
  41.  
  42. # We want some of the error fields to show up
  43. # under the service attribute names, rather than
  44. # the database column names, so here's what to
  45. # rename them to
  46. ERROR_FIELDS_TO_RENAME = {
  47. :template_path => :template_href
  48. }
  49.  
  50. def rename_error_fields!
  51. ERROR_FIELDS_TO_RENAME.each do |from, to|
  52. v = @errors.delete(from)
  53. @errors[to] = v
  54. end
  55. end
  56. end
Add Comment
Please, Sign In to add comment