<?php

namespace App\Exceptions;

use Openguru\OpenCartFramework\Contracts\ExceptionHandlerInterface;
use Openguru\OpenCartFramework\Http\JsonResponse;
use Openguru\OpenCartFramework\Http\Response;
use Openguru\OpenCartFramework\Telegram\Exceptions\TelegramInvalidSignatureException;
use Throwable;

class CustomExceptionHandler implements ExceptionHandlerInterface
{
    public function respond(Throwable $exception): ?JsonResponse
    {
        if ($exception instanceof TelegramInvalidSignatureException) {
            return new JsonResponse(['error' => 'Invalid Signature'], Response::HTTP_BAD_REQUEST);
        }

        return null;
    }
}
