<?php

namespace AuthStack\UserDirectory\Exceptions;

use Illuminate\Http\JsonResponse;

class PolicyException extends \Exception
{
    public function report()
    {}

    public function render(): JsonResponse
    {
        return response()->json(['error' => [$this->getMessage()]], $this->getHttpStatusCode());
    }

    public function getHttpStatusCode(): int
    {
        if(empty($this->getCode()) || 0 === $this->getCode())
        {
            return 422;
        }

        return (int)$this->getCode();
    }
}