Skip to content

Commit fcf58e5

Browse files
committed
Refactor code to handle empty response in email query
1 parent 9ed1806 commit fcf58e5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/flc.cr

+7-4
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,15 @@ else
260260
case query_type
261261
when "domain"
262262
credentials = JSON.parse(response.body)["items"].as_a
263+
263264
when "email"
264-
# sample data
265265
json_data = JSON.parse(response.body)
266-
passwords = json_data.as_a.first["passwords"].as_a
267-
# inject the identity name into the credentials
268-
credentials = passwords.map { |password| {"identity_name" => json_data.as_a.first["name"], "hash" => password["hash"], "imported_at" => password["imported_at"], "source" => password["source"]} }
266+
# if response is empty then exit
267+
unless json_data.as_a.empty?
268+
passwords = json_data.as_a.first["passwords"].as_a
269+
# inject the identity name into the credentials
270+
credentials = passwords.map { |password| {"identity_name" => json_data.as_a.first["name"], "hash" => password["hash"], "imported_at" => password["imported_at"], "source" => password["source"]} }
271+
end
269272
when "password"
270273
# sample data
271274
json_data = JSON.parse(response.body)

0 commit comments

Comments
 (0)