Undefined Array Key "errors" in LemonSqueezy API Method
Closed this issue · 4 comments
Lemon Squeezy for Laravel Version
1.5.4
Laravel Version
10.48
PHP Version
8.2
Description
In the LemonSqueezy.php
file, within the api
method, line 66, the following line causes an Undefined array key "errors"
error:
throw new LemonSqueezyApiError($response['errors'][0]['detail'], (int) $response['errors'][0]['status']);
This occurs because $response is not an array but an Illuminate\Http\Client\Response object. Attempting to access it as an array causes an undefined key error.
Proposed Fix:
Replace the problematic line with:
throw new LemonSqueezyApiError($response->json('message', ''), $response->status());
This uses the json method to extract the error message from the response body and the status method to get the HTTP status code.
Steps To Reproduce
Call the LemonSqueezy::api method with parameters that would result in an error response from the API. Example:
LemonSqueezy::api('get', 'invalid-endpoint')
But this shouldn't happen because Illuminate\Http\Client\Response
implements ArrayAccess
. It's perfectly fine to use array syntax on it. If you run into Undefined array key "errors"
then it means there's no such key even though the response failed. I wonder why.
Could you perhaps paste the entire response object you got back from Lemon Squeezy? Inspecting its contents could maybe show us where to look.
I've got same problem as well it happens all the time, when swap is performed. Response is successful, but it registers as failed and then it tries to resolve error and fails at doing it, because there is no error.
And stack trace ends at controller action, so it is very weird, that stack trace is also incomplete, seems like something crashes.
@juslintek there's three extra vendor frames after that line, maybe those help?
I'd need a clear way to reproduce this otherwise I'll be shooting in the dark.