-
Notifications
You must be signed in to change notification settings - Fork 0
Page size and error handling #12
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2dae09d
page size handling
MaestroError 518e4c0
Implement pagination for block children and data source queries
MaestroError e86e404
Fix styling
MaestroError c7b4483
Add NotionApiException for handling API error responses and implement…
MaestroError 94e3f69
Merge branch 'page-size-and-error-handling' of https://github.com/Red…
MaestroError dfde966
Fix styling
MaestroError 5b0def1
Update src/SDK/Requests/Actions/BlockChildren.php
MaestroError 9301725
Update src/SDK/Requests/Actions/QueryDataSource.php
MaestroError ae9fbb5
Fixes after review
MaestroError e2dade1
Fixes after review 2
MaestroError 84c8afa
Update src/Services/DatabaseReader.php
MaestroError File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Manual Test: Notion API Error Handling | ||
| * | ||
| * This script demonstrates how the SDK now throws NotionApiException | ||
| * when the Notion API returns an error response. | ||
| */ | ||
|
|
||
| require_once __DIR__.'/../vendor/autoload.php'; | ||
|
|
||
| use Redberry\MdNotion\SDK\Exceptions\NotionApiException; | ||
| use Redberry\MdNotion\SDK\Notion; | ||
|
|
||
| echo "=== Manual Test: Notion API Error Handling ===\n\n"; | ||
|
|
||
| // Test 1: Invalid Token | ||
| echo "Test 1: Invalid Token (401 Unauthorized)\n"; | ||
| echo str_repeat('-', 50)."\n"; | ||
|
|
||
| try { | ||
| $notion = new Notion('invalid-token', '2025-09-03'); | ||
| $notion->act()->getPage('some-page-id'); | ||
| echo "❌ Expected exception was not thrown\n"; | ||
| } catch (NotionApiException $e) { | ||
| echo "✅ NotionApiException caught!\n"; | ||
| echo ' Status: '.$e->getResponse()->status()."\n"; | ||
| echo ' Code: '.$e->getNotionCode()."\n"; | ||
| echo ' Message: '.$e->getNotionMessage()."\n"; | ||
| echo ' isUnauthorized(): '.($e->isUnauthorized() ? 'true' : 'false')."\n"; | ||
| echo ' isRetryable(): '.($e->isRetryable() ? 'true' : 'false')."\n"; | ||
| } catch (Exception $e) { | ||
| echo '❌ Unexpected exception: '.get_class($e)."\n"; | ||
| echo ' Message: '.$e->getMessage()."\n"; | ||
| } | ||
|
|
||
| echo "\n"; | ||
|
|
||
| // Test 2: Object Not Found (valid token, non-existent page) | ||
| echo "Test 2: Object Not Found (404)\n"; | ||
| echo str_repeat('-', 50)."\n"; | ||
|
|
||
| // Load real token if available | ||
| $tokenFile = __DIR__.'/../notion-token.php'; | ||
| if (file_exists($tokenFile)) { | ||
| $token = include $tokenFile; | ||
|
|
||
| try { | ||
| $notion = new Notion($token, '2025-09-03'); | ||
| // Try to fetch a non-existent page | ||
| $notion->act()->getPage('00000000-0000-0000-0000-000000000000'); | ||
| echo "❌ Expected exception was not thrown\n"; | ||
| } catch (NotionApiException $e) { | ||
| echo "✅ NotionApiException caught!\n"; | ||
| echo ' Status: '.$e->getResponse()->status()."\n"; | ||
| echo ' Code: '.$e->getNotionCode()."\n"; | ||
| echo ' Message: '.$e->getNotionMessage()."\n"; | ||
| echo ' isNotFound(): '.($e->isNotFound() ? 'true' : 'false')."\n"; | ||
| echo ' isRetryable(): '.($e->isRetryable() ? 'true' : 'false')."\n"; | ||
| } catch (Exception $e) { | ||
| echo '❌ Unexpected exception: '.get_class($e)."\n"; | ||
| echo ' Message: '.$e->getMessage()."\n"; | ||
| } | ||
| } else { | ||
| echo "⏭️ Skipped (no notion-token.php found)\n"; | ||
| } | ||
|
|
||
| echo "\n"; | ||
|
|
||
| // Test 3: Successful Request (for comparison) | ||
| echo "Test 3: Successful Request\n"; | ||
| echo str_repeat('-', 50)."\n"; | ||
|
|
||
| if (file_exists($tokenFile)) { | ||
| $token = include $tokenFile; | ||
|
|
||
| try { | ||
| $notion = new Notion($token, '2025-09-03'); | ||
| // Use a known valid page ID from your workspace | ||
| $response = $notion->act()->getPage('24cd937adaa8811c8dd5c2a5ed7eb453'); | ||
| echo "✅ Request successful!\n"; | ||
| echo ' Status: '.$response->status()."\n"; | ||
| echo ' Page ID: '.$response->json()['id']."\n"; | ||
| } catch (NotionApiException $e) { | ||
| echo '❌ NotionApiException: '.$e->getMessage()."\n"; | ||
| echo " You may need to update the page ID to one accessible by your integration.\n"; | ||
| } catch (Exception $e) { | ||
| echo '❌ Unexpected exception: '.get_class($e)."\n"; | ||
| echo ' Message: '.$e->getMessage()."\n"; | ||
| } | ||
| } else { | ||
| echo "⏭️ Skipped (no notion-token.php found)\n"; | ||
| } | ||
|
|
||
| echo "\n=== Error Handling Summary ===\n\n"; | ||
| echo "The SDK now throws NotionApiException for all API errors.\n"; | ||
| echo "Available helper methods:\n"; | ||
| echo " - getNotionCode() - Get the error code (e.g., 'unauthorized', 'object_not_found')\n"; | ||
| echo " - getNotionMessage() - Get the human-readable error message\n"; | ||
| echo " - isUnauthorized() - Check if 401 unauthorized\n"; | ||
| echo " - isForbidden() - Check if 403 restricted_resource\n"; | ||
| echo " - isNotFound() - Check if 404 object_not_found\n"; | ||
| echo " - isRateLimited() - Check if 429 rate_limited\n"; | ||
| echo " - isValidationError() - Check if 400 validation_error\n"; | ||
| echo " - isServerError() - Check if 5xx server error\n"; | ||
| echo " - isRetryable() - Check if error is retryable (rate limits, server errors, conflicts)\n"; | ||
| echo " - getResponse() - Access the full Saloon Response object\n"; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.