# frozen_string_literal: true # Refinements # ======================================================================= using NRSER # Definitions # ======================================================================= module Locd # Classes # ---------------------------------------------------------------------------- # Base class for errors that are to be expected and should be handled # gracefully. # class HandledError < StandardError; end # Base class for {HandledError} that happen during request processing which # should result in useful error responses to the user. # class RequestError < HandledError STATUS_CODE = 400 STATUS_MESSAGE = "Bad Request" def self.status "#{ self::STATUS_CODE } #{ self::STATUS_MESSAGE }" end # TODO document `text` attribute. # # @return [attr_type] # attr_reader :text def initialize text = self.class::STATUS_MESSAGE @text = text super "#{ self.class.status }\n\n#{ text }" end def to_http_response Locd.http_response_for self.class.status, text end def to_proxy_machine_cmd { close: to_http_response } end end # Raised when we couldn't find what the request seems to be looking for # (`404 Not Found` in HTTP). # class NotFoundError < RequestError STATUS_CODE = 404 STATUS_MESSAGE = "Not Found" end end # module Locd