Class: AtomicLti::ErrorHandlingMiddleware
- Inherits:
-
Object
- Object
- AtomicLti::ErrorHandlingMiddleware
- Defined in:
- lib/atomic_lti/error_handling_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ErrorHandlingMiddleware
constructor
A new instance of ErrorHandlingMiddleware.
- #render(status, body, format) ⇒ Object
- #render_error(status, message) ⇒ Object
Constructor Details
#initialize(app) ⇒ ErrorHandlingMiddleware
Returns a new instance of ErrorHandlingMiddleware.
3 4 5 |
# File 'lib/atomic_lti/error_handling_middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/atomic_lti/error_handling_middleware.rb', line 25 def call(env) @app.call(env) rescue JWT::ExpiredSignature render_error(401, "The launch has expired. Please launch the application again.") rescue JWT::DecodeError render_error(401, "The launch token is invalid.") rescue AtomicLti::Exceptions::NoLTIToken render_error(401, "Invalid launch. Please launch the application again.") rescue AtomicLti::Exceptions::AtomicLtiAuthException => e render_error(401, "Invalid LTI launch. Please launch the application again. #{e.}") rescue AtomicLti::Exceptions::AtomicLtiNotFoundException => e render_error(404, e.) rescue AtomicLti::Exceptions::AtomicLtiException => e render_error(500, "Invalid LTI launch. Please launch the application again. #{e.}") end |
#render(status, body, format) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/atomic_lti/error_handling_middleware.rb', line 14 def render(status, body, format) [ status, { "Content-Type" => "#{format}; charset=\"UTF-8\"", "Content-Length" => body.bytesize.to_s, }, [body], ] end |
#render_error(status, message) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/atomic_lti/error_handling_middleware.rb', line 7 def render_error(status, ) format = "text/plain" body = render(status, body, format) end |