dirkgroenen / pinterest-api-php

A PHP wrapper for the official Pinterest API. :pushpin:
https://developers.pinterest.com/docs/getting-started/introduction/
Apache License 2.0
173 stars 76 forks source link

Any way to ignore a fatal error when creating a pin #64

Closed gary-woods closed 7 years ago

gary-woods commented 7 years ago

Firstly, what an outstanding piece of code you have here. Thank you for piecing this together so that I don't have to!

When creating a pin, if the image URL leads to a 404 page, then we receive a fatal error. Is it possible to adjust the code so that it is not a fatal error which essentially stops the rest of the PHP code from running.

You can simply try it using an image URL that doesn't exist.

You will receive the following error:

Fatal error: Uncaught exception 'DirkGroenen\Pinterest\Exceptions\PinterestException' with message 'Pinterest error (code: 400) with message: Sorry we could not fetch the image.

in /Pinterest-API-PHP/src/Pinterest/Transport/Request.php:233 Stack trace: #0
dirkgroenen commented 7 years ago

The pin can't be placed so throwing an exception is kinda 'expected' behavior. If you want your code to continue so you can show something to your end-user you can always catch the exception in your code using a try/catch block

try {
    // your code
} catch(DirkGroenen\Pinterest\Exceptions\PinterestException $e) {
  // Do something or silently ignore
}