Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SheetCRUD
- module Error
- ERRORS = [
- unauthorized: { message: 'Unauthorized.', status: 401 },
- limit_exceed: { message: 'Rate limit exceed.', status: 429 },
- not_found: { message: 'Not found.', status: 404 }
- ]
- class StandardAPIError < StandardError
- attr_reader :status
- def initialize(message="Error.", status=500)
- @status = status
- super(message)
- end
- end
- ERRORS[0].each_pair do |klass_name, values|
- klass = Class.new(StandardAPIError) do
- define_method :initialize do |message = values[:message], status = values[:status]|
- super(message, status)
- end
- end
- Error.const_set(klass_name.to_s.camelize, klass)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement