Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limited exception message length #460

Open
lydenn opened this issue Sep 30, 2024 · 2 comments
Open

limited exception message length #460

lydenn opened this issue Sep 30, 2024 · 2 comments

Comments

@lydenn
Copy link

lydenn commented Sep 30, 2024

in the RequestException, exception message is set to limit only 200 characters. is there anyway to allow the message length more than that?

@Sammyjo20
Copy link
Member

I think this is just a limit set by Saloon, I'd be happy to accept a PR which increases this limit.

@juse-less
Copy link
Contributor

@lydenn Like Sam says, it's a limit in Saloon only (in the RequestException, like you said).
I don't think you can properly override the max body length property right now, unfortunately.

The way I've handled this is to create a custom Exception, and extend the RequestException, and in the constructor pass the message manually (to bypass this).
So something like this..

class MyRequestException extends \Saloon\Exceptions\Request\RequestException
{
    public function __construct(Response $response, ?string $message = null, int $code = 0, ?Throwable $previous = null)
    {
        $message ??= $response->body();

        parent::__construct($response, $message, $code, $previous);

        // Or to keep Saloons normal behaviour.
        // $this->maxBodyLength = mb_strlen($message ?? $response->body());
        //
        // parent::__construct($response, $message, $code, $previous);
    }
}

You will need to set your custom Exception, as shown here.
You don't necessarily need to extend the RequestException, but that's what I ended up doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants