pnp / pnpjs

Fluent JavaScript API for SharePoint and Microsoft Graph REST APIs
https://pnp.github.io/pnpjs/
Other
753 stars 305 forks source link

graph: Cancel Event Error Handling #2963

Closed kkazala closed 5 months ago

kkazala commented 5 months ago

Major Version

3.x

Minor Version Number

17

Target environment

NodeJS

Additional environment details

Local dev using service principal, with read/write to the shared mailbox

Authentication using

 this.credential = new DefaultAzureCredential();

this.graph = graphfi().using(
            GraphDefault(),
            AzureIdentity(this.credential, ["https://graph.microsoft.com/.default"], null)
        );

issue not related to the authentication, I can create/update/cancel events. Just the response is kinda wrong

Expected or Desired Behavior

Event should be cancelled (this works) and the repose should indicate success

Observed Behavior

Following example from #2942 I'm cancelling events in batch (see code below) The event is cancelled, the user receives an email with the message: image

However, an error is thrown: Cannot convert undefined or null to object the e.stack contains:

TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (<anonymous>)
    at hOP (file:///../node_modules/@pnp/core/util.js:138:34)
    at parseODataJSON (file:///../node_modules/@pnp/queryable/behaviors/parsers.js:50:9)
    at file:///../node_modules/@pnp/queryable/behaviors/parsers.js:12:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Proxy.<anonymous> (file:///.../node_modules/@pnp/queryable/behaviors/parsers.js:78:26)
    at async Timeout._onTimeout (file:///../node_modules/@pnp/queryable/queryable.js:120:50)'

Steps to Reproduce

        const calendar = this.graph.users.getById(sharedMailbox).calendar;
        const [batchedGraph, execute] = createBatch(calendar);
        calendar.using(batchedGraph);

cancelInvitations.forEach(x => {
            const eventsQuery = GraphQueryable(calendar.events.getById(x.EventId), `/cancel`);
            graphPost(eventsQuery, body{ comment: "Cancelling event"} ))
                .then(r =>
                    resDelete.push({
                        id: x.EventId,
                        success: true
                }))
                .catch(e =>
                    resDelete.push({
                        id: x.EventId,
                        success: false,
                        errStatus: e.status,
                        errMsg: e.message
                }));
        });
        await execute();

the code in #2942 throws the same error. I think it's not related to how I sent the request, but rather to how the response is parsed

patrick-rodgers commented 5 months ago

Based on the documentation this API call returns HTTP/1.1 202 Accepted and would not have a body.

Can you try using HeaderParse as a workaround?

import { HeaderParse } from "@pnp/queryable";

const eventsQuery = GraphQueryable(calendar.events.getById(x.EventId), `/cancel`);

eventsQuery.using(HeaderParse());

//...
kkazala commented 5 months ago

@patrick-rodgers It seems it was a fluke, because the same code, for the same tests, works OK today. I'm noting down your recommendation to use the HeaderParse for troubleshooting, I'm sure it will come handy sooner or later.

thx!

github-actions[bot] commented 5 months ago

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.