Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Translation] Crowdin provider throw Exception when status is 50x #47216

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

Closed

Conversation

alamirault
Copy link
Contributor

@alamirault alamirault commented Aug 7, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #45920
License MIT
Doc PR symfony/symfony-docs#...

When calling provider return server error, it was silently accepted (with warning log in some cases).
Now, ProviderException is thrown. This avoid [OK] New local translations has been sent when there is one failed call.

Only Crowdin provider is changed here. If it's right approach, I can edit this PR or create new one foreach provider

@carsonbot carsonbot added this to the 5.4 milestone Aug 7, 2022
@carsonbot carsonbot changed the title [Translator] Crowdin provider throw Exception when status is 50x [Translation] Crowdin provider throw Exception when status is 50x Aug 7, 2022
@@ -324,9 +348,7 @@ private function listStrings(int $fileId, int $limit, int $offset): array
]);

if (200 !== $response->getStatusCode()) {
$this->logger->error(sprintf('Unable to list strings for file %d: "%s".', $fileId, $response->getContent()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

$throw flag to getContent is true by default. So this warning cannot work with codes 3xx, 4xx, 5xx.
And only 200 is possible in 2xx (https://developer.crowdin.com/api/v2/#operation/api.projects.strings.getMany)

@alamirault alamirault force-pushed the hotfix/45920-push-pull-not-ok-if-500 branch from 476084b to df11ec7 Compare August 7, 2022 17:37
Copy link
Member

@welcoMattic welcoMattic left a comment

Choose a reason for hiding this comment

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

Thanks for this fix. I guess it's a good way to do. So, if you want, fee free to open new PRs for 2 other providers.

@fabpot
Copy link
Member

fabpot commented Aug 8, 2022

Let’s do everything in this PR of possible.

$response = $this->client->request('POST', sprintf('tags/%s.json', rawurlencode($tag)), [
'body' => implode(',', $idsWithoutComma),
]);
if ([] !== $idsWithoutComma) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoid calling provider when idsWithoutComma is empty. There is no asset to tag so I think is ok 😊

https://localise.biz/api/docs/tags/tagassets

@alamirault
Copy link
Contributor Author

Also done for Loco and Lokalise providers.

@fabpot
Copy link
Member

fabpot commented Aug 9, 2022

Thank you @alamirault.

fabpot added a commit that referenced this pull request Aug 9, 2022
… is 50x (alamirault)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Translation] Crowdin provider throw Exception when status is 50x

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #45920 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

When calling provider return server error, it was silently accepted (with warning log in some cases).
Now, `ProviderException` is thrown. This avoid `[OK] New local translations has been sent` when there is one failed call.

Only Crowdin provider is changed here. If it's right approach, I can edit this PR or create new one foreach provider

Commits
-------

3b7aed2 [Translation] Crowdin provider throw Exception when status is 50x
@fabpot fabpot closed this Aug 9, 2022
@fabpot fabpot force-pushed the hotfix/45920-push-pull-not-ok-if-500 branch from 06cfab4 to 3b7aed2 Compare August 9, 2022 14:34
This was referenced Aug 26, 2022
@fabpot fabpot mentioned this pull request Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants