Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

fix: classify Pinterest content-policy rejections (code 1) instead of surfacing raw JSON (#278)

Paulo Castellano120839213c5b
diff --git a/app/Exceptions/Social/PinterestPublishException.php b/app/Exceptions/Social/PinterestPublishException.php
index ca13f92ab..bfc4c7383 100644
--- a/app/Exceptions/Social/PinterestPublishException.php
+++ b/app/Exceptions/Social/PinterestPublishException.php
@@ -41,6 +41,32 @@ class PinterestPublishException extends SocialPublishException
);
}
+ // Documented for /pins, /media, and /boards alike (Pinterest's public
+ // OpenAPI spec: github.com/pinterest/api-description). In our flows
+ // this means the board (or, when polling media status, the media
+ // upload) referenced by the request no longer exists or isn't
+ // accessible to this account.
+ if ($status === 404) {
+ return new static(
+ userMessage: 'Pinterest could not find the selected board. It may have been deleted or you no longer have access to it.',
+ category: ErrorCategory::ContentPolicy,
+ platformErrorCode: (string) $status,
+ rawResponse: $rawResponse,
+ );
+ }
+
+ // Pinterest's own JSON error code 1 ("Sorry! This site doesn't allow
+ // you to save Pins.") is a content-policy rejection reused from their
+ // legacy "nopin" crawler-block message, not an HTTP/technical error.
+ if ($status === 400 && (int) data_get($body, 'code') === 1) {
+ return new static(
+ userMessage: "Pinterest rejected this pin. This usually means the content violates Pinterest's content policies (e.g. adult or sexual content).",
+ category: ErrorCategory::ContentPolicy,
+ platformErrorCode: (string) $status,
+ rawResponse: $rawResponse,
+ );
+ }
+
if ($status === 400 && str_contains(strtolower($rawResponse), 'board')) {
return new static(
userMessage: 'Invalid board. Please select a valid board.',
diff --git a/tests/Unit/Exceptions/Social/PinterestPublishExceptionTest.php b/tests/Unit/Exceptions/Social/PinterestPublishExceptionTest.php
index cbfc348ca..b3ca5123b 100644
--- a/tests/Unit/Exceptions/Social/PinterestPublishExceptionTest.php
+++ b/tests/Unit/Exceptions/Social/PinterestPublishExceptionTest.php
@@ -34,6 +34,26 @@ test('HTTP 403 maps to Permission category', function () {
->and($exception->userMessage)->toBe('Not authorized to create pins on this board.');
});
+test('HTTP 404 maps to ContentPolicy category', function () {
+ $response = Http::response(['code' => 2, 'message' => 'Board not found.'], 404);
+ $fakeResponse = Http::fake(['*' => $response])->post('https://api.pinterest.com/test');
+
+ $exception = PinterestPublishException::fromApiResponse($fakeResponse);
+
+ expect($exception->category)->toBe(ErrorCategory::ContentPolicy)
+ ->and($exception->userMessage)->toBe('Pinterest could not find the selected board. It may have been deleted or you no longer have access to it.');
+});
+
+test('HTTP 400 with Pinterest error code 1 maps to ContentPolicy category', function () {
+ $response = Http::response(['code' => 1, 'message' => "Sorry! This site doesn't allow you to save Pins."], 400);
+ $fakeResponse = Http::fake(['*' => $response])->post('https://api.pinterest.com/test');
+
+ $exception = PinterestPublishException::fromApiResponse($fakeResponse);
+
+ expect($exception->category)->toBe(ErrorCategory::ContentPolicy)
+ ->and($exception->userMessage)->toBe("Pinterest rejected this pin. This usually means the content violates Pinterest's content policies (e.g. adult or sexual content).");
+});
+
test('HTTP 400 with board in body maps to ContentPolicy category', function () {
$response = Http::response(['message' => 'Invalid board_id provided.'], 400);
$fakeResponse = Http::fake(['*' => $response])->post('https://api.pinterest.com/test');