Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f19f769

Browse filesBrowse files
committed
Show more detailed errors for QiitaAPIError
* header * mode * path
1 parent 6a24a3e commit f19f769
Copy full SHA for f19f769

File tree

2 files changed

+18
-3
lines changed
Filter options

2 files changed

+18
-3
lines changed

‎lib/error.rb

Copy file name to clipboardExpand all lines: lib/error.rb
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ def initialize(msg: 'A Qiita item ID is invalid.')
6868
end
6969

7070
class QiitaAPIError < StandardError
71-
def initialize(msg: 'A Qiita API returns a non-succeeded status.', response: nil)
72-
msg += " Status code: #{response.status}, Response body: #{JSON.parse(response.body)}" unless response.nil?
71+
def initialize(msg: 'A Qiita API returns a non-succeeded status.', data: nil)
72+
unless data.nil?
73+
msg += " Status code: #{data[:response].status}," \
74+
" Response body: #{JSON.parse(data[:response].body)}," \
75+
" Header: #{data[:header]}," \
76+
" Mode: \"#{data[:mode]}\", Path: \"#{data[:path]}\""
77+
end
78+
7379
super(msg)
7480
end
7581
end

‎lib/qiita.rb

Copy file name to clipboardExpand all lines: lib/qiita.rb
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ def publish
3737
connection.patch(&request_params)
3838
end
3939

40-
raise QiitaAPIError.new(response: response) unless response.status >= 200 && response.status < 300
40+
unless response.status >= 200 && response.status < 300
41+
raise QiitaAPIError.new(
42+
data: {
43+
response: response,
44+
header: @header,
45+
mode: @mode,
46+
path: @path
47+
}
48+
)
49+
end
4150

4251
JSON.parse(response.body)
4352
end

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.