forked from discourse/discourse_api
/
error.rb
39 lines (31 loc) · 821 Bytes
/
error.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module DiscourseApi
class DiscourseError < StandardError
attr_reader :response
def initialize(message, response = nil)
super(message)
@response = response
end
end
class Error < DiscourseError
attr_reader :wrapped_exception
# Initializes a new Error object
#
# @param exception [Exception, String]
# @return [DiscourseApi::Error]
def initialize(exception = $!)
@wrapped_exception = exception
exception.respond_to?(:message) ? super(exception.message) : super(exception.to_s)
end
end
class UnauthenticatedError < DiscourseError
end
class NotFoundError < DiscourseError
end
class UnprocessableEntity < DiscourseError
end
class TooManyRequests < DiscourseError
end
class Timeout < Error
end
end