{"record":{"id":"f12034b6f4190391","repo":"fullstackhero/dotnet-starter-kit","slug":"brand-query-brandid-not-found","errorCode":null,"errorMessage":"Brand {query.BrandId} not found.","messagePattern":"Brand (.+?) not found\\.","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"src/Modules/Catalog/Modules.Catalog/Features/v1/Brands/GetBrandById/GetBrandByIdQueryHandler.cs","lineNumber":21,"sourceCode":"using FSH.Modules.Catalog.Contracts.v1.Brands;\nusing FSH.Modules.Catalog.Data;\nusing Mediator;\nusing Microsoft.EntityFrameworkCore;\n\nnamespace FSH.Modules.Catalog.Features.v1.Brands.GetBrandById;\n\npublic sealed class GetBrandByIdQueryHandler(CatalogDbContext dbContext)\n    : IQueryHandler<GetBrandByIdQuery, BrandDto>\n{\n    public async ValueTask<BrandDto> Handle(GetBrandByIdQuery query, CancellationToken cancellationToken)\n    {\n        ArgumentNullException.ThrowIfNull(query);\n\n        var brand = await dbContext.Brands\n            .AsNoTracking()\n            .FirstOrDefaultAsync(b => b.Id == query.BrandId, cancellationToken)\n            .ConfigureAwait(false)\n            ?? throw new NotFoundException($\"Brand {query.BrandId} not found.\");\n\n        return new BrandDto(\n            brand.Id,\n            brand.Name,\n            brand.Slug,\n            brand.Description,\n            brand.LogoUrl,\n            brand.CreatedAtUtc,\n            brand.UpdatedAtUtc,\n            brand.DeletedOnUtc,\n            brand.DeletedBy);\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":35,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/Modules/Catalog/Modules.Catalog/Features/v1/Brands/GetBrandById/GetBrandByIdQueryHandler.cs#L3-L35","documentation":"GetBrandByIdQueryHandler queries dbContext.Brands (AsNoTracking) for the given BrandId and throws NotFoundException when no row matches, which the API surfaces as HTTP 404. Default query filters (soft-delete and tenant scoping) apply, so hidden or foreign-tenant rows look missing.","triggerScenarios":"Send/GetBrandById query with an unknown, hard-deleted, soft-deleted, or cross-tenant BrandId.","commonSituations":"Client cached an ID that was since deleted; user opens a bookmarked URL after the brand was removed; multitenancy header misconfigured so the row is invisible.","solutions":["Confirm the BrandId via the brands list endpoint","Restore the brand if it was soft-deleted (RestoreBrand endpoint)","Verify the tenant header matches the tenant owning the brand"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"bool exists = brands.Any(b => b.Id == id); // from a recently fetched list","typeGuard":null,"tryCatchPattern":"try { var brand = await mediator.Send(new GetBrandByIdQuery(id)); }\ncatch (NotFoundException) { return Results.NotFound($\"Brand {id} not found.\"); }","preventionTips":["Avoid persisting brand IDs in long-lived clients without refresh","Validate IDs belong to the active tenant","Handle soft-deleted entities explicitly in lookups"],"tags":["not-found","http-404","catalog","query"],"backgroundTag":"entity-not-found","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}