Skip to content

Commit

Permalink
[FIX] Translation not loaded due to misconfiguration.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisanalfa committed May 26, 2017
1 parent ae31c00 commit bacfd8c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 66 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
APP_ENV=local
APP_DEBUG=true
API_DEBUG=true
APP_KEY=aaaabbbbccccddddeeeeffffgggghhhh

DB_CONNECTION=mysql
Expand Down
40 changes: 5 additions & 35 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
namespace App\Exceptions;

use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;

class Handler extends ExceptionHandler
{
Expand All @@ -25,54 +22,27 @@ class Handler extends ExceptionHandler
ModelNotFoundException::class,
ValidationException::class,
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
parent::report($e);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof HttpException) {
return new JsonResponse([
'message' => $e->getMessage() ?: $this->getMessageFromClassName($e),
], $e->getStatusCode());
}

return parent::render($request, $e);
}

/**
* Get Message From Class Name.
*
* @param HttpException $e
*
* @return string
*/
protected function getMessageFromClassName(HttpException $e)
{
$class = get_class($e);
$file = Arr::last(explode('\\', $class));

return Str::snake(str_ireplace(
['HttpException', 'Exception'],
['', ''],
$file
));
}
}
37 changes: 7 additions & 30 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Http\Controllers\Controller;
use Tymon\JWTAuth\Exceptions\JWTException;
use Illuminate\Validation\ValidationException;
use Illuminate\Http\Exception\HttpResponseException;

class AuthController extends Controller
Expand All @@ -22,9 +23,12 @@ class AuthController extends Controller
public function postLogin(Request $request)
{
try {
$this->validatePostLoginRequest($request);
} catch (HttpResponseException $e) {
return $this->onBadRequest();
$this->validate($request, [
'email' => 'required|email|max:255',
'password' => 'required',
]);
} catch (ValidationException $e) {
return $e->getResponse();
}

try {
Expand All @@ -43,33 +47,6 @@ public function postLogin(Request $request)
return $this->onAuthorized($token);
}

/**
* Validate authentication request.
*
* @param Request $request
* @return void
* @throws HttpResponseException
*/
protected function validatePostLoginRequest(Request $request)
{
$this->validate($request, [
'email' => 'required|email|max:255',
'password' => 'required',
]);
}

/**
* What response should be returned on bad request.
*
* @return JsonResponse
*/
protected function onBadRequest()
{
return new JsonResponse([
'message' => 'bad_request'
], Response::HTTP_BAD_REQUEST);
}

/**
* What response should be returned on invalid credentials.
*
Expand Down
27 changes: 26 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Encryption Key
Expand All @@ -12,7 +13,31 @@
|
*/

'key' => env('APP_KEY'),
'key' => env('APP_KEY', 'aaaabbbbccccddddeeeeffffgggghhhh'),

'cipher' => 'AES-256-CBC',

/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => env('APP_LOCALE', 'en'),
/*
|--------------------------------------------------------------------------
| Application Fallback Locale
|--------------------------------------------------------------------------
|
| The fallback locale determines the locale to use when the current one
| is not available. You may change the value to correspond to any of
| the language folders that are provided through your application.
|
*/
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),

];

0 comments on commit bacfd8c

Please sign in to comment.