Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. module SheetCRUD
  2. module Error
  3.  
  4. ERRORS = [
  5. unauthorized: { message: 'Unauthorized.', status: 401 },
  6. limit_exceed: { message: 'Rate limit exceed.', status: 429 },
  7. not_found: { message: 'Not found.', status: 404 }
  8. ]
  9.  
  10. class StandardAPIError < StandardError
  11. attr_reader :status
  12.  
  13. def initialize(message="Error.", status=500)
  14. @status = status
  15. super(message)
  16. end
  17. end
  18.  
  19. ERRORS[0].each_pair do |klass_name, values|
  20. klass = Class.new(StandardAPIError) do
  21. define_method :initialize do |message = values[:message], status = values[:status]|
  22. super(message, status)
  23. end
  24. end
  25.  
  26. Error.const_set(klass_name.to_s.camelize, klass)
  27. end
  28.  
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement