Rename error classes

This commit is contained in:
Matt Jankowski 2024-10-30 15:46:46 -04:00
parent 1577b99c75
commit a714587002
13 changed files with 13 additions and 13 deletions

View File

@ -23,7 +23,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController
def unknown_affected_account? def unknown_affected_account?
json = JSON.parse(body) json = JSON.parse(body)
json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.exists?(uri: json['actor']) json.is_a?(Hash) && %w(Delete Update).include?(json['type']) && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.exists?(uri: json['actor'])
rescue Oj::ParseError rescue JSON::ParserError
false false
end end

View File

@ -196,7 +196,7 @@ module JsonLdHelper
return if compare_id.present? && json['id'] != compare_id return if compare_id.present? && json['id'] != compare_id
json json
rescue Oj::ParseError rescue JSON::ParserError
nil nil
end end

View File

@ -114,7 +114,7 @@ class Admin::Metrics::Dimension::SoftwareVersionsDimension < Admin::Metrics::Dim
value: version, value: version,
human_value: version, human_value: version,
} }
rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, Oj::ParseError rescue Terrapin::CommandNotFoundError, Terrapin::ExitStatusError, JSON::ParserError
nil nil
end end

View File

@ -265,7 +265,7 @@ class LinkDetailsExtractor
next unless structured_data.valid? next unless structured_data.valid?
structured_data structured_data
rescue Oj::ParseError, EncodingError rescue JSON::ParserError, EncodingError
Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" } Rails.logger.debug { "Invalid JSON-LD in #{@original_url}" }
next next
end.first end.first

View File

@ -78,7 +78,7 @@ class TranslationService::DeepL < TranslationService
provider: 'DeepL.com' provider: 'DeepL.com'
) )
end end
rescue Oj::ParseError rescue JSON::ParserError
raise UnexpectedResponseError raise UnexpectedResponseError
end end
end end

View File

@ -55,7 +55,7 @@ class TranslationService::LibreTranslate < TranslationService
provider: 'LibreTranslate' provider: 'LibreTranslate'
) )
end end
rescue Oj::ParseError rescue JSON::ParserError
raise UnexpectedResponseError raise UnexpectedResponseError
end end
end end

View File

@ -9,7 +9,7 @@ class VideoMetadataExtractor
@metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true) @metadata = JSON.parse(ffmpeg_command_output, symbolize_names: true)
parse_metadata parse_metadata
rescue Terrapin::ExitStatusError, Oj::ParseError rescue Terrapin::ExitStatusError, JSON::ParserError
@invalid = true @invalid = true
rescue Terrapin::CommandNotFoundError rescue Terrapin::CommandNotFoundError
raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffprobe` command. Please install ffmpeg.' raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffprobe` command. Please install ffmpeg.'

View File

@ -57,7 +57,7 @@ class Webfinger
def perform def perform
Response.new(@uri, body_from_webfinger) Response.new(@uri, body_from_webfinger)
rescue Oj::ParseError rescue JSON::ParserError
raise Webfinger::Error, "Invalid JSON in response for #{@uri}" raise Webfinger::Error, "Invalid JSON in response for #{@uri}"
rescue Addressable::URI::InvalidURIError rescue Addressable::URI::InvalidURIError
raise Webfinger::Error, "Invalid URI for #{@uri}" raise Webfinger::Error, "Invalid URI for #{@uri}"

View File

@ -19,7 +19,7 @@ class ActivityPub::FetchRemoteActorService < BaseService
else else
body_to_json(prefetched_body, compare_id: uri) body_to_json(prefetched_body, compare_id: uri)
end end
rescue Oj::ParseError rescue JSON::ParserError
raise Error, "Error parsing JSON-LD document #{uri}" raise Error, "Error parsing JSON-LD document #{uri}"
end end

View File

@ -61,7 +61,7 @@ class ActivityPub::ProcessAccountService < BaseService
end end
@account @account
rescue Oj::ParseError rescue JSON::ParserError
nil nil
end end

View File

@ -38,7 +38,7 @@ class ActivityPub::ProcessCollectionService < BaseService
else else
process_items [@json] process_items [@json]
end end
rescue Oj::ParseError rescue JSON::ParserError
nil nil
end end

View File

@ -86,7 +86,7 @@ class FetchOEmbedService
end end
validate(parse_for_format(body)) if body.present? validate(parse_for_format(body)) if body.present?
rescue Oj::ParseError, Ox::ParseError rescue JSON::ParserError, Ox::ParseError
nil nil
end end

View File

@ -22,7 +22,7 @@ class SoftwareUpdateCheckService < BaseService
Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res| Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res|
return JSON.parse(res.body_with_limit) if res.code == 200 return JSON.parse(res.body_with_limit) if res.code == 200
end end
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError rescue *Mastodon::HTTP_CONNECTION_ERRORS, JSON::ParserError
nil nil
end end