2.9 KiB
2.9 KiB
task, cycles, context, private, started, finished
| task | cycles | context | private | started | finished |
|---|---|---|---|---|---|
| Fix GET /api/public/cooperative/:hash returning 500 instead of 404 for invalid hash | 3 | true | false | 2026-05-16T16:00:46Z | 2026-05-16T16:01:15Z |
files
- app/Http/Controllers/Market/CooperativeController.php [lines 390-403] —
publicGetCooperativemethod; usesresponse()->json()instead ofResponse::json() - routes/web.php [line 673] —
Route::get('/api/public/cooperative/{hkey}', ...)— no auth middleware, public
steps
- In
CooperativeController::publicGetCooperative()replaceresponse()->json()calls withResponse::json()using the Hypervel facade. Adduse Hypervel\Support\Facades\Response;import if not present. - Wrap the
Organization::where(...)query in a try/catch to return a clean 500 JSON error (not bare Server Error page) if the DB call itself fails. - Also audit
publicRegisterMember()(lines 405-450) for the sameresponse()->json()pattern and fix there too.
context
// BROKEN (lines 390-403):
public function publicGetCooperative(Request $request, string $hkey)
{
$cooperative = Organization::where('hashkey', $hkey)
->where('type', 'COOPERATIVE')
->where('is_active', true)
->select(['id', 'hashkey', 'name', 'type', ...])
->first();
if (!$cooperative) {
return response()->json(['success' => false, 'message' => 'Cooperative not found'], 404);
// ^ Should be Response::json() — response() helper may not exist in Hypervel
}
return response()->json(['success' => true, 'data' => $cooperative]);
}
// FIX:
use Hypervel\Support\Facades\Response;
public function publicGetCooperative(Request $request, string $hkey)
{
try {
$cooperative = Organization::where('hashkey', $hkey)
->where('type', 'COOPERATIVE')
->where('is_active', true)
->select(['id', 'hashkey', 'name', 'type', 'cooperative_type', 'cooperative_category', 'contact_person', 'contact_number', 'address'])
->first();
} catch (\Throwable $e) {
return Response::json(['success' => false, 'message' => 'Service temporarily unavailable'], 500);
}
if (!$cooperative) {
return Response::json(['success' => false, 'message' => 'Cooperative not found'], 404);
}
return Response::json(['success' => true, 'data' => $cooperative]);
}
Impact: RegisterCoop.vue fetches GET /api/public/cooperative/{hkey} to render the public self-registration form. An invalid hash in the URL crashes the server instead of showing "Cooperative not found." This also affects the public cooperative registration QR code links shared by cooperatives — any typo or expired link causes a confusing server error.
notes
- dictionary: ai-docs/dictionary.md (organizations table =
organizations, cooperative members =cooperative_members) - linters: none
- constraints: Use
Response::json()facade (Hypervel), notresponse()->json()(Laravel global helper).