Skip to content

fix(mistral): report a validation error instead of failing with a TypeError - #1061

Open
skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/mistral-validation-error
Open

skybleak333 wants to merge 1 commit into
prism-php:mainfrom
skybleak333:fix/mistral-validation-error

Conversation

@skybleak333

Copy link
Copy Markdown

Description

When Mistral rejects a request at validation (422), the message of the error body is not a string but the list of invalid fields:

{"object":"error","message":{"detail":[{"type":"float_type","loc":["body","top_p"],"msg":"Input should be a valid number","input":"high"}]},"type":"invalid_request_error","param":null,"code":null}

#283 handled that in ValidatesResponse, but a 4xx now goes through handleRequestException(), which passed the array to PrismException::providerRequestErrorWithDetails(?string $errorMessage). So instead of a PrismException, the call failed with TypeError: ... Argument #4 ($errorMessage) must be of type ?string, array given, and the details were lost.

The message is now JSON encoded when it's an array, as ValidatesResponse does, so the exception reads Mistral Error [422]: invalid_request_error - {"detail":[...]}.

The body in the new test is the shape from #282. The test fails with that TypeError without the change. The full suite, PHPStan, Pint and Rector pass.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant