Skip to content

Commit

Permalink
fix: Wrap upsert function error handling (#22)
Browse files Browse the repository at this point in the history
* fix: Wrap upsert function error handling

* Update changelog

* Remove rc changelogs

* tests: Update upsert testing

---------

Co-authored-by: livramatheus <[email protected]>
  • Loading branch information
symplivra and livramatheus authored Oct 4, 2024
1 parent 16d67ec commit a62c5a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 42 deletions.
34 changes: 4 additions & 30 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
[5.0.0]

[Changes](https://github.com/Symplicity/outlook/releases/tag/5.0.0)

[5.0.0-rc7]

- Update scopes when migrating from outlook v1 rest apis to graph ([4cdb0e1](https://github.com/Symplicity/outlook/commit/4cdb0e19eb36f9787fed64caf0b204f113f2c694))

[5.0.0-rc6]

- Factor out batchPush vs push ([f157b49](https://github.com/Symplicity/outlook/commit/f157b49a161e55688379b8bac1a88dc5ff7bac1b))

[5.0.0-rc5]
[5.0.1]

- Allow header & options in `getInstancesViewRequestConfiguration`
- Replace original timezone to startDate timezone in occurrence date method
- Update upsert function to throw an Exception in case of any errors during the request

[5.0.0-rc4]

- Add new method `getInstancesCollection` to get instances of a series master in collection format.

[5.0.0-rc3]

- Restrict kiota-authentication-phpleague to 1.0.*

[5.0.0-rc2]

- Restrict graph-core to 2.0.*
- Restrict graph-sdk to 2.2.*

[5.0.0-rc1]
[5.0.0]

- Graph API release candidate
[Changes](https://github.com/Symplicity/outlook/releases/tag/5.0.0)

[5.0.0-alpha]

Expand Down
27 changes: 16 additions & 11 deletions src/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,22 @@ protected function batchPush(array $eventsToWrite, array $params = [], array $ar
*/
public function upsert(Event $event, array $args = []): ?GraphEvent
{
$postRequestConfiguration = $this->getEventPostRequestConfiguration();
$patchRequestConfiguration = $this->getEventPatchRequestConfiguration();

$eventUpsertRequest = $this->prepareUpsertAsync(
$event,
$postRequestConfiguration,
$patchRequestConfiguration,
$args
);

return $eventUpsertRequest->wait();
try {
$postRequestConfiguration = $this->getEventPostRequestConfiguration();
$patchRequestConfiguration = $this->getEventPatchRequestConfiguration();

$eventUpsertRequest = $this->prepareUpsertAsync(
$event,
$postRequestConfiguration,
$patchRequestConfiguration,
$args
);

$response = $eventUpsertRequest->wait();
return $response;
} catch (\Exception $e) {
$this->convertToReadableError($e);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testUpsertEvent()
$contents = $request->getBody()->getContents();
$this->assertJsonStringEqualsJsonString('{"@odata.type":"#microsoft.graph.event","end":{"dateTime":"2023-12-05 14:00:00","timeZone":"Eastern Standard Time"},"start":{"dateTime":"2023-12-05 13:00:00","timeZone":"Eastern Standard Time"},"subject":"test"}', $contents);

$this->expectException(RequestException::class);
$this->expectException(ReadError::class);
$this->stub->upsert($event, ['client' => $client]);
}

Expand Down

0 comments on commit a62c5a0

Please sign in to comment.