Last active
September 26, 2018 23:10
-
-
Save JamesTheHacker/9537ee4efa12b2b42b9810e0089e9ffb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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