Skip to content

Commit

Permalink
具象独自例外 ServerErrorExeption を定義
Browse files Browse the repository at this point in the history
  • Loading branch information
okashoi committed Mar 17, 2019
1 parent 4700720 commit 00fd572
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/app/Exceptions/ServerErrorException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Exceptions;

use Throwable;

/**
* Class ServerErrorException
* @package App\Exceptions
*/
class ServerErrorException extends MyAppException
{
/**
* @var array
*/
protected $context;

/**
* ServerErrorException constructor.
* @param array $context
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(array $context = [], string $message = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
$this->context = $context;
}

/**
* @return array ログ出力時の追加情報
*/
public function getContext(): array
{
return $this->context;
}

/**
* @return int HTTP ステータスコード
*/
public function getStatusCode(): int
{
return 500;
}

/**
* @return string ユーザ向けのメッセージ
*/
public function getUserMessage(): string
{
return 'サーバエラーが発生しました。もう一度同じ操作をお試しください。問題が解消しない場合は、お問い合わせ窓口よりご報告をお願いいたします。';
}
}

0 comments on commit 00fd572

Please sign in to comment.