mirror of
https://github.com/Blockstream/satellite-api.git
synced 2024-11-19 13:00:02 +01:00
return an error when a date cannot be parsed
This commit is contained in:
parent
2ce1e1e59a
commit
638dcdffdd
12
main.rb
12
main.rb
@ -58,7 +58,11 @@ end
|
||||
# array of JSON orders sorted in reverse chronological order
|
||||
get '/orders/sent' do
|
||||
param :before, String, required: false, default: lambda { Time.now.utc.iso8601 }
|
||||
before = DateTime.iso8601(params[:before])
|
||||
begin
|
||||
before = DateTime.iso8601(params[:before])
|
||||
rescue
|
||||
halt 400, {:message => "Invalid date", :errors => ["Couldn't parse date given by before param"]}.to_json
|
||||
end
|
||||
Order.where(status: :sent).where("created_at < ?", before)
|
||||
.select(Order::PUBLIC_FIELDS)
|
||||
.order(ended_transmission_at: :desc)
|
||||
@ -72,7 +76,11 @@ end
|
||||
# array of JSON orders sorted in reverse chronological order
|
||||
get '/orders/pending' do
|
||||
param :before, String, required: false, default: lambda { Time.now.utc.iso8601 }
|
||||
before = DateTime.iso8601(params[:before])
|
||||
begin
|
||||
before = DateTime.iso8601(params[:before])
|
||||
rescue
|
||||
halt 400, {:message => "Invalid date", :errors => ["Couldn't parse date given by before param"]}.to_json
|
||||
end
|
||||
Order.where(status: :pending).where("created_at < ?", before)
|
||||
.select(Order::PUBLIC_FIELDS)
|
||||
.order(created_at: :desc)
|
||||
|
Loading…
Reference in New Issue
Block a user