Skip to content

Commit

Permalink
Return 404 when order is not found
Browse files Browse the repository at this point in the history
Current implementation is very happy-path oriented. When order exists,
everything is fine. However, when there is no order, then the
NoMethodError (as in honeybadger) is thrown.

The behaviour is changed now. The 404 page is returned when
there is no order for given id.

https://app.honeybadger.io/projects/58419/faults/91462781/01J3Y753P7F6F70CYT2ZQE1VND
#342
  • Loading branch information
lukaszreszke committed Jul 29, 2024
1 parent ec93d4d commit 4878e71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rails_application/app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ def index

def show
@order = Orders::Order.find_by_uid(params[:id])

return not_found unless @order

@order_lines = Orders::OrderLine.where(order_uid: @order.uid)
@shipment = Shipments::Shipment.find_by(order_uid: @order.uid)
@invoice = Invoices::Invoice.find_or_initialize_by(order_uid: @order.uid)
Expand Down Expand Up @@ -128,4 +131,8 @@ def authorize_payment_cmd(order_id)
def capture_payment_cmd(order_id)
Payments::CapturePayment.new(order_id: order_id)
end

def not_found
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
end
end
5 changes: 5 additions & 0 deletions rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def test_expiring_orders
assert_select("td", "Expired")
end

def test_order_not_found
get "/orders/123"
assert_response :not_found
end

def test_cancel
shopify_id = register_customer("Shopify")

Expand Down

0 comments on commit 4878e71

Please sign in to comment.