Skip to content

3.x / Handle error when uploading too fast #29

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

Merged
merged 1 commit into from
Apr 15, 2019
Merged

Conversation

j0k3r
Copy link
Owner

@j0k3r j0k3r commented Apr 15, 2019

Fix error message when user is uploading too fast.
Related #23

@j0k3r j0k3r merged commit 6e9ba91 into 3.x Apr 15, 2019
@j0k3r j0k3r deleted the 3/fix-uploading-too-fast branch April 15, 2019 09:45
$message = 'Request failed with: "' . $responseData['data']['error'] . '"';
$errorMessage = $responseData['data']['error'];
// when uploading too fast, error is an array
if (\is_array($responseData['data']['error']) && isset($responseData['data']['error']['message'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about this condition.

Is it possible that the $responseData['data']['error']['message'] is not set?

If it's possible, the $responseData['data']['error'] will be the array. And it will be the Notice message about Array to string conversion.

Consider following approach:

......
 if (\is_array($responseData['data']['error']) {
    ......
    $errorMessage = $responseData['data']['error']['message'] ?? '';
    ......
}
......

It will avoid the Notice message correctly :).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know because I do not have other cases where the error key is an array. Maybe it can be an array without the message key. We don't know.

Also, using ?? is PHP 7.? but the project still needs to work on PHP 5.6 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j0k3r, thank you for your reply.

To be compatible with php-5.6, perhaps we can consider following code snippet :) :

$errorMessage = isset($responseData['data']['error']['message']) ? $responseData['data']['error']['message'] : '';

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.

2 participants