Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bulk request実行時のエラーレスポンスが取得できるように #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/kintone/kintone_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class Kintone::KintoneError < StandardError
attr_reader :message_text, :id, :code, :http_status, :errors

def initialize(messages, http_status)
if messages.is_a?(Hash) && messages.has_key?('results')
messages = messages['results'].find { |message| message.has_key?('message') }
end
@message_text = messages['message']
@id = messages['id']
@code = messages['code']
Expand Down
50 changes: 50 additions & 0 deletions spec/kintone/kintone_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,55 @@
it { is_expected.to eq '必須です。' }
end
end

context 'bulk requestでValidation Errorが発生した場合' do
let(:messages) do
{
'results' =>
[
{
"code" => "CB_VA01",
"id" => "49ZYc7Nv0dbvJ7N4lVEu",
"message" => "入力内容が正しくありません。",
"errors" => {
"record.取消"=> {
"messages"=>["必須です。"]
}
}
},
{}
]
}
end

let(:http_status) { 400 }

it { is_expected.to eq '400 [CB_VA01] 入力内容が正しくありません。(49ZYc7Nv0dbvJ7N4lVEu)' }

describe '#message_text' do
subject { target.message_text }
it { is_expected.to eq '入力内容が正しくありません。' }
end

describe '#id' do
subject { target.id }
it { is_expected.to eq '49ZYc7Nv0dbvJ7N4lVEu' }
end

describe '#code' do
subject { target.code }
it { is_expected.to eq 'CB_VA01' }
end

describe '#http_status' do
subject { target.http_status }
it { is_expected.to eq 400 }
end

describe '#errors' do
subject { target.errors['record.取消']['messages'].first }
it { is_expected.to eq '必須です。' }
end
end
end
end