lib/micro/case/error.rb in u-case-3.0.0.rc1 vs lib/micro/case/error.rb in u-case-3.0.0.rc2
- old
+ new
@@ -15,22 +15,25 @@
class InvalidResultType < TypeError
def initialize; super('type must be a Symbol'.freeze); end
end
- class InvalidResultData < TypeError
- end
+ class InvalidResult < TypeError
+ def initialize(is_success, type, use_case)
+ base =
+ "The result returned from #{use_case.class.name}#call! must be a Hash."
- class InvalidSuccessResult < InvalidResultData
- def initialize(object)
- super("Success(result: #{object.inspect}) must be a Hash or Symbol")
- end
- end
+ result = is_success ? 'Success'.freeze : 'Failure'.freeze
- class InvalidFailureResult < InvalidResultData
- def initialize(object)
- super("Failure(result: #{object.inspect}) must be a Hash, Symbol or an Exception")
+ example =
+ if type === :ok || type === :error || type === :exception
+ "#{result}(result: { key: 'value' })"
+ else
+ "#{result}(:#{type}, result: { key: 'value' })"
+ end
+
+ super("#{base}\n\nExample:\n #{example}")
end
end
class InvalidResultInstance < ArgumentError
def initialize; super('argument must be an instance of Micro::Case::Result'.freeze); end
@@ -47,10 +50,10 @@
class InvalidAccessToTheUseCaseObject < StandardError
def initialize; super('only a failure result can access its use case object'.freeze); end
end
def self.by_wrong_usage?(exception)
- exception.is_a?(InvalidResultData) || exception.is_a?(Error::UnexpectedResult) || exception.is_a?(ArgumentError)
+ exception.is_a?(InvalidResult) || exception.is_a?(UnexpectedResult) || exception.is_a?(ArgumentError)
end
end
end
end