fix(listings): return 404 instead of 500 for non-existent listing detail

Move not-found handling from the query handler to the controller layer
following DDD conventions: the handler now returns null when a listing
is not found, and the controller maps that to NotFoundException (404).

Key changes:
- Handler returns ListingDetailData | null instead of throwing
- Use ListingNotFoundSignal to prevent caching null results
- Add `return await` to properly catch errors in try/catch
- Controller throws NotFoundException with listing ID in message
- Strengthen E2E test to assert exactly 404 (was [404, 400])
- Add unit tests: not-found returns null, unexpected error → 500
- Fix missing LoggerService mock in handler test

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-13 00:21:42 +07:00
parent 2c97f99214
commit 50b2eea4a2
5 changed files with 78 additions and 8 deletions

View File

@@ -142,7 +142,7 @@ test.describe('Listings API', () => {
const res = await request.get('listings/non-existent-id-12345');
expect(res.ok()).toBeFalsy();
expect([404, 400]).toContain(res.status());
expect(res.status()).toBe(404);
});
});