SlideShare a Scribd company logo
1 of 39
Download to read offline
okashoi@Laravel Meetup Tokyo Vol.12
•
•
• ← New!!
• 6
• LT 1
• 🙇 #LaravelTokyo
!2
!3
!4
!5


https://speakerdeck.com/suzuken/phpcon2017
!6
•
•
•
•
•
!7
HttpException 😄
!8
• ←DONE
•
•
!9
•
•
•
!10
• AppExceptionsHandler
• report()
• HTTP render()
• IlluminateFoundationExceptionsHandler
• AppExceptionsHandler
• report()
• HTTP render()
• IlluminateFoundationExceptionsHandler
IlluminateFoundationExceptionsHandler::render()
!13
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
IlluminateFoundationExceptionsHandler::render()
!14
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
render
IlluminateFoundationExceptionsHandler::render()
!15
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
IlluminateFoundationExceptionsHandler::render()
!16
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
IlluminateFoundationExceptionsHandler::render()
!17
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
Contet-Type ON/OFF
•
•
•
!18
!19
<?php
namespace AppExceptions;
/**
* Class MyAppException
* @package AppExceptions
*/
abstract class MyAppException extends Exception
{
/**
* @return int HTTP ステータスコード
*/
abstract public function getStatusCode(): int;
/**
* @return string ユーザ向けのメッセージ
*/
abstract public function getUserMessage(): string;
}
!20
<?php
namespace AppExceptions;
/**
* Class MyAppException
* @package AppExceptions
*/
abstract class MyAppException extends Exception
{
/**
* @return int HTTP ステータスコード
*/
abstract public function getStatusCode(): int;
/**
* @return string ユーザ向けのメッセージ
*/
abstract public function getUserMessage(): string;
}
HTTP
!21
<?php
namespace AppExceptions;
/**
* Class MyAppException
* @package AppExceptions
*/
abstract class MyAppException extends Exception
{
/**
* @return int HTTP ステータスコード
*/
abstract public function getStatusCode(): int;
/**
* @return string ユーザ向けのメッセージ
*/
abstract public function getUserMessage(): string;
}
AppExceptionsHandler
• report() 🙆
• HTTP 

getStatusCode() getUserMessage()
• →
!22
IlluminateFoundationExceptionsHandler::render()
!23
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
IlluminateFoundationExceptionsHandler::render()
!24
/**
* Render an exception into a response.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse
*/
public function render($request, Exception $e)
{
if (method_exists($e, 'render') && $response = $e->render($request)) {
return Router::toResponse($request, $response);
} elseif ($e instanceof Responsable) {
return $e->toResponse($request);
}
$e = $this->prepareException($e);
if ($e instanceof HttpResponseException) {
return $e->getResponse();
} elseif ($e instanceof AuthenticationException) {
return $this->unauthenticated($request, $e);
} elseif ($e instanceof ValidationException) {
return $this->convertValidationExceptionToResponse($e, $request);
}
return $request->expectsJson()
? $this->prepareJsonResponse($request, $e)
: $this->prepareResponse($request, $e);
}
IlluminateFoundationExceptionsHandler::prepareResponse()
!25
/**
* Prepare a response for the given exception.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return SymfonyComponentHttpFoundationResponse
*/
protected function prepareResponse($request, Exception $e)
{
if (! $this->isHttpException($e) && config('app.debug')) {
return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
}
if (! $this->isHttpException($e)) {
$e = new HttpException(500, $e->getMessage());
}
return $this->toIlluminateResponse(
$this->renderHttpException($e), $e
);
}
IlluminateFoundationExceptionsHandler::prepareResponse()
!26
/**
* Prepare a response for the given exception.
*
* @param IlluminateHttpRequest $request
* @param Exception $e
* @return SymfonyComponentHttpFoundationResponse
*/
protected function prepareResponse($request, Exception $e)
{
if (! $this->isHttpException($e) && config('app.debug')) {
return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
}
if (! $this->isHttpException($e)) {
$e = new HttpException(500, $e->getMessage());
}
return $this->toIlluminateResponse(
$this->renderHttpException($e), $e
);
}
SymfonyComponentHttpKernelExceptionHttpException 

HTTP
HttpException 

😄
!27
HttpException 😄
!28
<?php
namespace AppExceptions;
use SymfonyComponentHttpKernelExceptionHttpException;
/**
* Class MyAppException
* @package AppExceptions
*/
abstract class MyAppException extends Exception
{
/**
* @return int HTTP ステータスコード
*/
abstract public function getStatusCode(): int;
/**
* @return string ユーザ向けのメッセージ
*/
abstract public function getUserMessage(): string;
/**
* @return HttpException
*/
public function toHttpException(): HttpException
{
return new HttpException(
$this->getStatusCode(),
$this->getUserMessage(),
$this->getPrevious(),
[],
$this->code
);
}
}
※ JSON
AppExceptionsHandler
!29
/**
* Render an exception into an HTTP response.
*
* @param IlluminateHttpRequest $request
* @param Exception $exception
* @return IlluminateHttpResponse
*/
public function render($request, Exception $exception)
{
// 既存の render の仕組みを活用するため、HttpException に変換する
if ($exception instanceof MyAppException) {
$exception = $exception->toHttpException();
}
return parent::render($request, $exception);
}
!30
<?php
namespace AppExceptions;
use Throwable;
/**
* Class HogeException
* @package AppExceptions
*/
abstract class HogeException extends MyAppException
{
/**
* @return int HTTP ステータスコード
*/
public function getStatusCode(): int
{
return 500;
}
/**
* @return string ユーザ向けのメッセージ
*/
public function getUserMessage(): string
{
return 'ごめん';
}
}
•
• throw new HogeException('エラーです');

•
• Blade 

$exception->getMessage()

HTTP 

HttpException 😄
!31
•
• Laravel 404 

!32
+α URL
https://github.com/okashoi/colab-techbook6-example
!33
!34


!35
IlluminateFoundationExceptionsHandler::report()
!36
/**
* Report or log an exception.
*
* @param Exception $e
* @return mixed
*
* @throws Exception
*/
public function report(Exception $e)
{
if ($this->shouldntReport($e)) {
return;
}
if (is_callable($reportCallable = [$e, 'report'])) {
return $this->container->call($reportCallable);
}
try {
$logger = $this->container->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $e;
}
$logger->error(
$e->getMessage(),
array_merge($this->context(), ['exception' => $e]
));
}
IlluminateFoundationExceptionsHandler::report()
!37
/**
* Report or log an exception.
*
* @param Exception $e
* @return mixed
*
* @throws Exception
*/
public function report(Exception $e)
{
if ($this->shouldntReport($e)) {
return;
}
if (is_callable($reportCallable = [$e, 'report'])) {
return $this->container->call($reportCallable);
}
try {
$logger = $this->container->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $e;
}
$logger->error(
$e->getMessage(),
array_merge($this->context(), ['exception' => $e]
));
}
IlluminateFoundationExceptionsHandler::report()
!38
/**
* Report or log an exception.
*
* @param Exception $e
* @return mixed
*
* @throws Exception
*/
public function report(Exception $e)
{
if ($this->shouldntReport($e)) {
return;
}
if (is_callable($reportCallable = [$e, 'report'])) {
return $this->container->call($reportCallable);
}
try {
$logger = $this->container->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $e;
}
$logger->error(
$e->getMessage(),
array_merge($this->context(), ['exception' => $e]
));
}
report()
IlluminateFoundationExceptionsHandler::report()
!39
/**
* Report or log an exception.
*
* @param Exception $e
* @return mixed
*
* @throws Exception
*/
public function report(Exception $e)
{
if ($this->shouldntReport($e)) {
return;
}
if (is_callable($reportCallable = [$e, 'report'])) {
return $this->container->call($reportCallable);
}
try {
$logger = $this->container->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $e;
}
$logger->error(
$e->getMessage(),
array_merge($this->context(), ['exception' => $e]
));
}
context

More Related Content

What's hot

Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyAlessandro Cucci
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Workhorse Computing
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendKirill Chebunin
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
A new way to develop with WordPress!
A new way to develop with WordPress!A new way to develop with WordPress!
A new way to develop with WordPress!David Sanchez
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design PatternsBobby Bouwmann
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloadedRalf Eggert
 

What's hot (20)

Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
Getting Testy With Perl6
Getting Testy With Perl6Getting Testy With Perl6
Getting Testy With Perl6
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Symfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friendSymfony2 Service Container: Inject me, my friend
Symfony2 Service Container: Inject me, my friend
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Kyiv.py #17 Flask talk
Kyiv.py #17 Flask talkKyiv.py #17 Flask talk
Kyiv.py #17 Flask talk
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
A new way to develop with WordPress!
A new way to develop with WordPress!A new way to develop with WordPress!
A new way to develop with WordPress!
 
Flask SQLAlchemy
Flask SQLAlchemy Flask SQLAlchemy
Flask SQLAlchemy
 
PHP7 Presentation
PHP7 PresentationPHP7 Presentation
PHP7 Presentation
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloaded
 

Similar to エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo

Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Kacper Gunia
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowKacper Gunia
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Elena Kolevska
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with YieldJason Myers
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Jakub Zalas
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challengervanphp
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHPSharon Levy
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConRafael Dohms
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in actionJace Ju
 

Similar to エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo (20)

Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Functional php
Functional phpFunctional php
Functional php
 
Generating Power with Yield
Generating Power with YieldGenerating Power with Yield
Generating Power with Yield
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12Symfony components in the wild, PHPNW12
Symfony components in the wild, PHPNW12
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
The Truth About Lambdas in PHP
The Truth About Lambdas in PHPThe Truth About Lambdas in PHP
The Truth About Lambdas in PHP
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 

More from Shohei Okada

「登壇しているひとは偉い」という話
「登壇しているひとは偉い」という話「登壇しているひとは偉い」という話
「登壇しているひとは偉い」という話Shohei Okada
 
PHP-FPM の子プロセス制御方法と設定をおさらいしよう
PHP-FPM の子プロセス制御方法と設定をおさらいしようPHP-FPM の子プロセス制御方法と設定をおさらいしよう
PHP-FPM の子プロセス制御方法と設定をおさらいしようShohei Okada
 
PHP 8.0 の新記法を試してみよう!
PHP 8.0 の新記法を試してみよう!PHP 8.0 の新記法を試してみよう!
PHP 8.0 の新記法を試してみよう!Shohei Okada
 
自分たちのコードを Composer パッケージに分割して開発する
自分たちのコードを Composer パッケージに分割して開発する自分たちのコードを Composer パッケージに分割して開発する
自分たちのコードを Composer パッケージに分割して開発するShohei Okada
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumai
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumaiクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumai
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumaiShohei Okada
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaShohei Okada
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondoクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondoShohei Okada
 
スペシャリストとして組織をつくる、というキャリア
スペシャリストとして組織をつくる、というキャリアスペシャリストとして組織をつくる、というキャリア
スペシャリストとして組織をつくる、というキャリアShohei Okada
 
PHP でも活用できる Makefile
PHP でも活用できる MakefilePHP でも活用できる Makefile
PHP でも活用できる MakefileShohei Okada
 
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよ
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよはじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよ
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよShohei Okada
 
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...Shohei Okada
 
働き方が大きく変わった 入社3年目のときのとあるエピソード
働き方が大きく変わった 入社3年目のときのとあるエピソード働き方が大きく変わった 入社3年目のときのとあるエピソード
働き方が大きく変わった 入社3年目のときのとあるエピソードShohei Okada
 
Laravel で API バージョニングを実装するなら
Laravel で API バージョニングを実装するならLaravel で API バージョニングを実装するなら
Laravel で API バージョニングを実装するならShohei Okada
 
Laravel における Blade 拡張のツラミ
Laravel における Blade 拡張のツラミLaravel における Blade 拡張のツラミ
Laravel における Blade 拡張のツラミShohei Okada
 
Laravel の paginate は一体何をやっているのか
Laravel の paginate は一体何をやっているのかLaravel の paginate は一体何をやっているのか
Laravel の paginate は一体何をやっているのかShohei Okada
 
2017 年度を振り返って ~アウトプット編~
2017 年度を振り返って ~アウトプット編~2017 年度を振り返って ~アウトプット編~
2017 年度を振り返って ~アウトプット編~Shohei Okada
 
Laravel × レイヤードアーキテクチャをやってみている話
Laravel × レイヤードアーキテクチャをやってみている話Laravel × レイヤードアーキテクチャをやってみている話
Laravel × レイヤードアーキテクチャをやってみている話Shohei Okada
 
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみた
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみたLaravel 5.6 デフォルトの例外ハンドリング処理をまとめてみた
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみたShohei Okada
 
チームで「きちんと」Laravel を使っていくための取り組み
チームで「きちんと」Laravel を使っていくための取り組みチームで「きちんと」Laravel を使っていくための取り組み
チームで「きちんと」Laravel を使っていくための取り組みShohei Okada
 
プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話Shohei Okada
 

More from Shohei Okada (20)

「登壇しているひとは偉い」という話
「登壇しているひとは偉い」という話「登壇しているひとは偉い」という話
「登壇しているひとは偉い」という話
 
PHP-FPM の子プロセス制御方法と設定をおさらいしよう
PHP-FPM の子プロセス制御方法と設定をおさらいしようPHP-FPM の子プロセス制御方法と設定をおさらいしよう
PHP-FPM の子プロセス制御方法と設定をおさらいしよう
 
PHP 8.0 の新記法を試してみよう!
PHP 8.0 の新記法を試してみよう!PHP 8.0 の新記法を試してみよう!
PHP 8.0 の新記法を試してみよう!
 
自分たちのコードを Composer パッケージに分割して開発する
自分たちのコードを Composer パッケージに分割して開発する自分たちのコードを Composer パッケージに分割して開発する
自分たちのコードを Composer パッケージに分割して開発する
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumai
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumaiクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumai
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #shuuumai
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
 
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondoクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
 
スペシャリストとして組織をつくる、というキャリア
スペシャリストとして組織をつくる、というキャリアスペシャリストとして組織をつくる、というキャリア
スペシャリストとして組織をつくる、というキャリア
 
PHP でも活用できる Makefile
PHP でも活用できる MakefilePHP でも活用できる Makefile
PHP でも活用できる Makefile
 
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよ
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよはじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよ
はじめての Go 言語のプロジェクトを AWS Lambda + API Gateway でやったのでパッケージ構成を晒すよ
 
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...
Laravel × レイヤードアーキテクチャを実践して得られた知見と反省 / Practice of Laravel with layered archi...
 
働き方が大きく変わった 入社3年目のときのとあるエピソード
働き方が大きく変わった 入社3年目のときのとあるエピソード働き方が大きく変わった 入社3年目のときのとあるエピソード
働き方が大きく変わった 入社3年目のときのとあるエピソード
 
Laravel で API バージョニングを実装するなら
Laravel で API バージョニングを実装するならLaravel で API バージョニングを実装するなら
Laravel で API バージョニングを実装するなら
 
Laravel における Blade 拡張のツラミ
Laravel における Blade 拡張のツラミLaravel における Blade 拡張のツラミ
Laravel における Blade 拡張のツラミ
 
Laravel の paginate は一体何をやっているのか
Laravel の paginate は一体何をやっているのかLaravel の paginate は一体何をやっているのか
Laravel の paginate は一体何をやっているのか
 
2017 年度を振り返って ~アウトプット編~
2017 年度を振り返って ~アウトプット編~2017 年度を振り返って ~アウトプット編~
2017 年度を振り返って ~アウトプット編~
 
Laravel × レイヤードアーキテクチャをやってみている話
Laravel × レイヤードアーキテクチャをやってみている話Laravel × レイヤードアーキテクチャをやってみている話
Laravel × レイヤードアーキテクチャをやってみている話
 
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみた
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみたLaravel 5.6 デフォルトの例外ハンドリング処理をまとめてみた
Laravel 5.6 デフォルトの例外ハンドリング処理をまとめてみた
 
チームで「きちんと」Laravel を使っていくための取り組み
チームで「きちんと」Laravel を使っていくための取り組みチームで「きちんと」Laravel を使っていくための取り組み
チームで「きちんと」Laravel を使っていくための取り組み
 
プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話プロダクトに 1 から Vue.js を導入した話
プロダクトに 1 から Vue.js を導入した話
 

Recently uploaded

Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 

Recently uploaded (20)

Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 

エラー時にログに出力する情報と画面に表示する情報を分ける #LaravelTokyo

  • 2. • • • ← New!! • 6 • LT 1 • 🙇 #LaravelTokyo !2
  • 3. !3
  • 4. !4
  • 11. • AppExceptionsHandler • report() • HTTP render() • IlluminateFoundationExceptionsHandler
  • 12. • AppExceptionsHandler • report() • HTTP render() • IlluminateFoundationExceptionsHandler
  • 13. IlluminateFoundationExceptionsHandler::render() !13 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); }
  • 14. IlluminateFoundationExceptionsHandler::render() !14 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); } render
  • 15. IlluminateFoundationExceptionsHandler::render() !15 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); }
  • 16. IlluminateFoundationExceptionsHandler::render() !16 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); }
  • 17. IlluminateFoundationExceptionsHandler::render() !17 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); } Contet-Type ON/OFF
  • 19. !19 <?php namespace AppExceptions; /** * Class MyAppException * @package AppExceptions */ abstract class MyAppException extends Exception { /** * @return int HTTP ステータスコード */ abstract public function getStatusCode(): int; /** * @return string ユーザ向けのメッセージ */ abstract public function getUserMessage(): string; }
  • 20. !20 <?php namespace AppExceptions; /** * Class MyAppException * @package AppExceptions */ abstract class MyAppException extends Exception { /** * @return int HTTP ステータスコード */ abstract public function getStatusCode(): int; /** * @return string ユーザ向けのメッセージ */ abstract public function getUserMessage(): string; } HTTP
  • 21. !21 <?php namespace AppExceptions; /** * Class MyAppException * @package AppExceptions */ abstract class MyAppException extends Exception { /** * @return int HTTP ステータスコード */ abstract public function getStatusCode(): int; /** * @return string ユーザ向けのメッセージ */ abstract public function getUserMessage(): string; }
  • 22. AppExceptionsHandler • report() 🙆 • HTTP 
 getStatusCode() getUserMessage() • → !22
  • 23. IlluminateFoundationExceptionsHandler::render() !23 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); }
  • 24. IlluminateFoundationExceptionsHandler::render() !24 /** * Render an exception into a response. * * @param IlluminateHttpRequest $request * @param Exception $e * @return IlluminateHttpResponse|SymfonyComponentHttpFoundationResponse */ public function render($request, Exception $e) { if (method_exists($e, 'render') && $response = $e->render($request)) { return Router::toResponse($request, $response); } elseif ($e instanceof Responsable) { return $e->toResponse($request); } $e = $this->prepareException($e); if ($e instanceof HttpResponseException) { return $e->getResponse(); } elseif ($e instanceof AuthenticationException) { return $this->unauthenticated($request, $e); } elseif ($e instanceof ValidationException) { return $this->convertValidationExceptionToResponse($e, $request); } return $request->expectsJson() ? $this->prepareJsonResponse($request, $e) : $this->prepareResponse($request, $e); }
  • 25. IlluminateFoundationExceptionsHandler::prepareResponse() !25 /** * Prepare a response for the given exception. * * @param IlluminateHttpRequest $request * @param Exception $e * @return SymfonyComponentHttpFoundationResponse */ protected function prepareResponse($request, Exception $e) { if (! $this->isHttpException($e) && config('app.debug')) { return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e); } if (! $this->isHttpException($e)) { $e = new HttpException(500, $e->getMessage()); } return $this->toIlluminateResponse( $this->renderHttpException($e), $e ); }
  • 26. IlluminateFoundationExceptionsHandler::prepareResponse() !26 /** * Prepare a response for the given exception. * * @param IlluminateHttpRequest $request * @param Exception $e * @return SymfonyComponentHttpFoundationResponse */ protected function prepareResponse($request, Exception $e) { if (! $this->isHttpException($e) && config('app.debug')) { return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e); } if (! $this->isHttpException($e)) { $e = new HttpException(500, $e->getMessage()); } return $this->toIlluminateResponse( $this->renderHttpException($e), $e ); } SymfonyComponentHttpKernelExceptionHttpException 
 HTTP
  • 28. HttpException 😄 !28 <?php namespace AppExceptions; use SymfonyComponentHttpKernelExceptionHttpException; /** * Class MyAppException * @package AppExceptions */ abstract class MyAppException extends Exception { /** * @return int HTTP ステータスコード */ abstract public function getStatusCode(): int; /** * @return string ユーザ向けのメッセージ */ abstract public function getUserMessage(): string; /** * @return HttpException */ public function toHttpException(): HttpException { return new HttpException( $this->getStatusCode(), $this->getUserMessage(), $this->getPrevious(), [], $this->code ); } } ※ JSON
  • 29. AppExceptionsHandler !29 /** * Render an exception into an HTTP response. * * @param IlluminateHttpRequest $request * @param Exception $exception * @return IlluminateHttpResponse */ public function render($request, Exception $exception) { // 既存の render の仕組みを活用するため、HttpException に変換する if ($exception instanceof MyAppException) { $exception = $exception->toHttpException(); } return parent::render($request, $exception); }
  • 30. !30 <?php namespace AppExceptions; use Throwable; /** * Class HogeException * @package AppExceptions */ abstract class HogeException extends MyAppException { /** * @return int HTTP ステータスコード */ public function getStatusCode(): int { return 500; } /** * @return string ユーザ向けのメッセージ */ public function getUserMessage(): string { return 'ごめん'; } } • • throw new HogeException('エラーです');
 • • Blade 
 $exception->getMessage()
 HTTP 

  • 34. !34
  • 36. IlluminateFoundationExceptionsHandler::report() !36 /** * Report or log an exception. * * @param Exception $e * @return mixed * * @throws Exception */ public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } if (is_callable($reportCallable = [$e, 'report'])) { return $this->container->call($reportCallable); } try { $logger = $this->container->make(LoggerInterface::class); } catch (Exception $ex) { throw $e; } $logger->error( $e->getMessage(), array_merge($this->context(), ['exception' => $e] )); }
  • 37. IlluminateFoundationExceptionsHandler::report() !37 /** * Report or log an exception. * * @param Exception $e * @return mixed * * @throws Exception */ public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } if (is_callable($reportCallable = [$e, 'report'])) { return $this->container->call($reportCallable); } try { $logger = $this->container->make(LoggerInterface::class); } catch (Exception $ex) { throw $e; } $logger->error( $e->getMessage(), array_merge($this->context(), ['exception' => $e] )); }
  • 38. IlluminateFoundationExceptionsHandler::report() !38 /** * Report or log an exception. * * @param Exception $e * @return mixed * * @throws Exception */ public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } if (is_callable($reportCallable = [$e, 'report'])) { return $this->container->call($reportCallable); } try { $logger = $this->container->make(LoggerInterface::class); } catch (Exception $ex) { throw $e; } $logger->error( $e->getMessage(), array_merge($this->context(), ['exception' => $e] )); } report()
  • 39. IlluminateFoundationExceptionsHandler::report() !39 /** * Report or log an exception. * * @param Exception $e * @return mixed * * @throws Exception */ public function report(Exception $e) { if ($this->shouldntReport($e)) { return; } if (is_callable($reportCallable = [$e, 'report'])) { return $this->container->call($reportCallable); } try { $logger = $this->container->make(LoggerInterface::class); } catch (Exception $ex) { throw $e; } $logger->error( $e->getMessage(), array_merge($this->context(), ['exception' => $e] )); } context