Commit e6b5ad91 authored by Brett Walker's avatar Brett Walker

Return nil rather than raising an error

parent 448bc31b
......@@ -5,17 +5,15 @@
module Gitlab
module Utils
class MimeType
Error = Class.new(StandardError)
class << self
def from_io(io)
raise Error, "input isn't an IO object" unless io.is_a?(IO) || io.is_a?(StringIO)
return unless io.is_a?(IO) || io.is_a?(StringIO)
MimeMagic.by_magic(io).try(:type)
end
def from_string(string)
raise Error, "input isn't a string" unless string.is_a?(String)
return unless string.is_a?(String)
MimeMagic.by_magic(string)
end
......
......@@ -10,8 +10,8 @@ RSpec.describe Gitlab::Utils::MimeType do
context "input isn't an IO" do
let(:io) { "test" }
it "raises an error" do
expect { subject }.to raise_error(Gitlab::Utils::MimeType::Error)
it "returns nil" do
expect(subject).to be_nil
end
end
......@@ -42,8 +42,8 @@ RSpec.describe Gitlab::Utils::MimeType do
context "input isn't a string" do
let(:str) { nil }
it "raises an error" do
expect { subject }.to raise_error(Gitlab::Utils::MimeType::Error)
it "returns nil" do
expect(subject).to be_nil
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment