Skip to content

Instantly share code, notes, and snippets.

@JamesTheHacker
Last active September 26, 2018 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesTheHacker/9537ee4efa12b2b42b9810e0089e9ffb to your computer and use it in GitHub Desktop.
Save JamesTheHacker/9537ee4efa12b2b42b9810e0089e9ffb to your computer and use it in GitHub Desktop.
public function add($request, $response, $args) {
$user = $request->getParsedBody();
if(!$user) {
throw new \Exception('Failed to add user: $user is null');
return;
}
$validator = \API\Validators\UserRegistration::validate();
$this->logger->info('User:', [$user]);
try {
$validator->assert($user);
} catch (NestedValidationException $e) {
$this->logger->warning('Validation Failed!', [$e]);
$errors = $e->findMessages([
'snapchat_name' => 'Enter a valid snapchat name',
'age' => 'You must be over 18',
'gender' => 'Are you an alien?',
'password' => 'Enter a secure password',
'country' => 'Select your country of residence'
]);
return $response
->withStatus(200)
->withJson([
"success" => false,
"errors" => $errors
]);
}
[2018-09-26 23:00:06] slim.ERROR: Application Error: ["[object] (Exception(code: 0): Failed to add user: $user is null at /var/www/html/src/Controllers/User.php:63)"] []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment