Skip to content

Commit

Permalink
独自例外の抽象基底クラスを定義
Browse files Browse the repository at this point in the history
  • Loading branch information
okashoi committed Mar 17, 2019
1 parent 935f7a7 commit 4700720
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/app/Exceptions/MyAppException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Exceptions;

use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* Class MyAppException
* @package App\Exceptions
*/
abstract class MyAppException extends \Exception
{
/**
* @return array ログ出力時の追加情報
*/
abstract public function getContext(): array;

/**
* @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
);
}
}

0 comments on commit 4700720

Please sign in to comment.