fix: exception handling retuns json
This commit is contained in:
parent
bc551bf52b
commit
7977ec90b4
|
|
@ -140,6 +140,9 @@ return [
|
|||
'new_message' => 'New message',
|
||||
'payment_reviewed' => 'Payment has been reviewed',
|
||||
'product_reviewed' => 'Post has been reviewed',
|
||||
'api' => [
|
||||
'sign_up_excp' => 'Registration error',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -140,6 +140,9 @@ return [
|
|||
'new_message' => 'Новое сообщение',
|
||||
'payment_reviewed' => 'Платеж рассмотрен',
|
||||
'product_reviewed' => 'Объявление рассмотрено',
|
||||
'api' => [
|
||||
'sign_up_excp' => 'Ошибка при регистрации',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -142,6 +142,9 @@ return [
|
|||
'new_message' => 'Täze hat',
|
||||
'payment_reviewed' => 'Töleg gözden geçirildi',
|
||||
'product_reviewed' => 'Bildiriş gözden geçirildi',
|
||||
'api' => [
|
||||
'sign_up_excp' => 'Hasaba alyş ýalňyşy',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -109,11 +109,16 @@ Route::group(['prefix' => 'api'], function() {
|
|||
$credentials = Input::only($login_fields);
|
||||
|
||||
$rules = [
|
||||
'email' => 'required|between:6,191|email',
|
||||
'username' => 'required|digits_between:8,20|numeric',
|
||||
'email' => 'required|between:6,191|email|unique:users',
|
||||
'username' => 'required|numeric|unique:users',
|
||||
'dial_code' => 'required',
|
||||
];
|
||||
|
||||
// to check username
|
||||
$credentials = array_merge($credentials,[
|
||||
'username' => $credentials['dial_code'] . $credentials['username']
|
||||
]);
|
||||
|
||||
$validation = \Validator::make($credentials, $rules,(new UserModel)->messages);
|
||||
if ($validation->fails()) {
|
||||
return Response::json(['error' => $validation->errors()], 400);
|
||||
|
|
@ -130,9 +135,7 @@ Route::group(['prefix' => 'api'], function() {
|
|||
if (!array_key_exists('password_confirmation', $credentials) && array_key_exists('password', $credentials)) {
|
||||
$credentials['password_confirmation'] = $credentials['password'];
|
||||
}
|
||||
$userModel = Auth::register(array_merge($credentials,[
|
||||
'username' => $credentials['dial_code'] . $credentials['username']
|
||||
]), $automaticActivation);
|
||||
$userModel = Auth::register($credentials, $automaticActivation);
|
||||
|
||||
if ($userModel->methodExists('getAuthApiSignupAttributes')) {
|
||||
$user = $userModel->getAuthApiSignupAttributes();
|
||||
|
|
@ -151,7 +154,14 @@ Route::group(['prefix' => 'api'], function() {
|
|||
];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return Response::json(['error' => $e->getMessage()], 401);
|
||||
|
||||
\Log::info($e->getMessage());
|
||||
|
||||
return Response::json(['error' => [
|
||||
'ru' => trans('validation.api.sign_up_excp', [], 'ru'),
|
||||
'en' => trans('validation.api.sign_up_excp', [], 'en'),
|
||||
'tm' => trans('validation.api.sign_up_excp', [], 'tm'),
|
||||
]], 401);
|
||||
}
|
||||
|
||||
$token = JWTAuth::fromUser($userModel);
|
||||
|
|
|
|||
Loading…
Reference in New Issue