Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] return error message on invalid dob (rebase 24.1) #8279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/api/php/endpoints/candidates.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator
$pscid,
$project->getId()
);
} catch (\LorisException $e) {
} catch (\LorisException | \InvalidArgumentException $e) {
return new \LORIS\Http\Response\JSON\BadRequest($e->getMessage());
}

Expand Down
13 changes: 9 additions & 4 deletions php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ define('PSCID_NOT_UNIQUE', 3);
define('PSCID_INVALID_STRUCTURE', 4);
define('EDC_NOT_SPECIFIED', 5);
define('DOB_NOT_SPECIFIED', 6);
define('DOB_INVALID', 7);

/**
* Wrapper around a candidate in Loris. Mostly, it gets information
Expand Down Expand Up @@ -240,15 +241,19 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource,
EDC_NOT_SPECIFIED
);
}
if ($dateOfBirth !== null
&& (DateTime::createFromFormat('Y-m-d', $dateOfBirth) === false
|| empty($dateOfBirth))
) {
if (empty($dateOfBirth)) {
throw new InvalidArgumentException(
"Date of Birth must be specified",
DOB_NOT_SPECIFIED
);
}
$dob = DateTime::createFromFormat('!Y-m-d', $dateOfBirth);
if ($dob === false) {
throw new InvalidArgumentException(
"Date of Birth is invalid (expected format: YYYY-MM-DD)",
DOB_INVALID
);
}

if ($PSCIDSettings['generation'] == 'user') {
// check pscid is specified
Expand Down