Files
2026-10-25 23:19:29 -06:00

41 lines
1002 B
Ruby

# frozen_string_literal: true
module FO::HTTP
module Error
HTTP_ERROR_TYPES = {
NotFound: {
status: 404,
msg: 'We could not find the requested resource...',
name: 'Bad Request'
},
BadRequest: {
status: 400,
msg: 'We were unable to process your request, check your input and try again later',
name: 'Bad Request'
},
InternalServer: {
status: 500,
msg: 'Something went very wrong on our end!',
name: 'Internal Server Error'
}
}
class Base < StandardError
attr_reader :status, :msg, :name
end
FO::HTTP::Error::HTTP_ERROR_TYPES.each { |k,v|
clazz = Class.new(FO::HTTP::Error::Base) do
define_method(:initialize) do
super(v[:msg])
v.each { |attr, attr_value| self.set }
@status = v[:status]
@msg = v[:msg]
@name = v[:name]
end
end
FO::HTTP::Error.const_set(k, clazz)
}
end
end