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

Get client error code #38

Closed
Eternal1306 opened this issue Aug 23, 2017 · 2 comments
Closed

Get client error code #38

Eternal1306 opened this issue Aug 23, 2017 · 2 comments

Comments

@Eternal1306
Copy link

Hello, in my attempt to create albums automatically, I have realized, that if the UrlName already exists, it directly does not return anything to me, but I skip the 409 client error, but without being object or anything.

How can I get this code to control it with an if?

My idea is that if it already exists, add a number to the UrlName using a function, and if that also exists, add 1 to the previous number. This part has already been solved, I lack control if it exists...

Thanks in advance!

@lildude
Copy link
Owner

lildude commented Aug 23, 2017

The best thing to do is catch the GuzzleHttp\Exception\ClientException exception Guzzle throws when you attempt to create an album that already exists with that name, adjust the name by appending 1 to the number and try again.

For example:

try {
  $response = $client->post('folder/user/example/Cats!albums', $options);
} catch (GuzzleHttp\Exception\ClientException $e) {
  if ($e->getCode() == 409) {
     // retry code here
  };
}

You may want to put this in a for or while loop to keep incrementing until you finally get a unique name.

@lildude
Copy link
Owner

lildude commented Sep 20, 2017

I'm gonna take the silence on this issue as confirmation that you're resolved all your issues and I've answered all your questions. If you have any further issues or questions, please feel free to open a new issue.

@lildude lildude closed this as completed Sep 20, 2017
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

2 participants