FIX_NONEB_HR_API_CONTENT_TYPE_ISSUE

This commit is contained in:
velz 2026-03-31 17:48:12 +05:30
parent 3f7594355d
commit 73f54fd5f0

View File

@ -206,7 +206,11 @@ class NonEbClaimApiController extends BaseController
return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401); return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401);
} }
$body = $this->request->getJSON(true) ?? $this->request->getPost(); $rawBody = $this->request->getBody();
$isJson = str_contains($this->request->getHeaderLine('Content-Type'), 'application/json');
$body = ($isJson || ($rawBody !== '' && $rawBody !== null))
? (json_decode($rawBody, true) ?? $this->request->getPost())
: $this->request->getPost();
// Validate minimal user-facing fields only // Validate minimal user-facing fields only
$rules = [ $rules = [
@ -363,7 +367,11 @@ class NonEbClaimApiController extends BaseController
return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401); return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401);
} }
try {
$body = $this->request->getJSON(true) ?? []; $body = $this->request->getJSON(true) ?? [];
} catch (\Throwable $e) {
return $this->respond(['status' => false, 'code' => 400, 'message' => 'Invalid JSON body'], 400);
}
$page = max(1, (int)($body['page'] ?? 1)); $page = max(1, (int)($body['page'] ?? 1));
$per_page = min(100, max(1, (int)($body['per_page'] ?? 20))); $per_page = min(100, max(1, (int)($body['per_page'] ?? 20)));
$offset = ($page - 1) * $per_page; $offset = ($page - 1) * $per_page;
@ -544,7 +552,11 @@ class NonEbClaimApiController extends BaseController
return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401); return $this->respond(['status' => false, 'code' => 401, 'message' => 'Unauthorized'], 401);
} }
try {
$body = $this->request->getJSON(true) ?? $this->request->getPost(); $body = $this->request->getJSON(true) ?? $this->request->getPost();
} catch (\Throwable $e) {
return $this->respond(['status' => false, 'code' => 400, 'message' => 'Invalid JSON body'], 400);
}
$client_id_md5 = trim($body['client_id'] ?? ''); $client_id_md5 = trim($body['client_id'] ?? '');
$client_branch_id = (int)($body['client_branch_id'] ?? 0); $client_branch_id = (int)($body['client_branch_id'] ?? 0);