You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2024. It is now read-only.
When one or more requests in a batch fail, you cannot access the error from the body of the response.
Console Errors: [Is there any console error]
Screenshots: [If applicable, add screenshots to help explain your problem]
Steps to Reproduce
Authenticate in your app with only User.Read.
Run code:
// Create a batch request step to GET /me
let userRequestStep: MicrosoftGraph.BatchRequestStep = {
id: "1",
request: new Request("/me", {
method: "GET"
})
}
let today = moment({hour: 0, minute: 0, seconds: 0});
// Create a batch request step to add an event
let newEvent: Event = {
subject: "File end-of-day report",
start: {
// 5:00 PM
dateTime: today.add(17, "hours")
.format("YYYY-MM-DDTHH:mm:ss"),
timeZone: moment.tz.guess()
},
end: {
// 5:30 PM
dateTime: today.add(17, "hours").add(30, "minutes")
.format("YYYY-MM-DDTHH:mm:ss"),
timeZone: moment.tz.guess()
}
}
let addEventRequestStep: MicrosoftGraph.BatchRequestStep = {
id: "2",
// This step will happen after step 1
dependsOn: [ "1" ],
request: new Request("/me/events", {
method: "POST",
body: JSON.stringify(newEvent),
headers: {
"Content-Type": "application/json"
}
})
}
// Create the batch request content with the steps created
// above
let batchRequestContent = new MicrosoftGraph.BatchRequestContent([
userRequestStep,
addEventRequestStep
]);
let content = await batchRequestContent.getContent();
// POST the batch request content to the /$batch endpoint
let batchResponse = await client
.api('/$batch')
.post(content);
// Get the create event response by id
let newEventResponse = batchResponseContent.getResponseById("2");
if (!newEventResponse.ok) {
let error: any = await newEventResponse.json();
}
Second request will fail with a 403 since the app does not have the Calendars.ReadWrite scope.
Expected behavior: The error object in the body of the response (verified by Fiddler) should be returned.
Actual behavior: An error is logged to the console:
SyntaxError: Unexpected token o in JSON at position 1
at Object.doDependentBatchRequest [as selectedSample] (GraphService.ts:295)
at async Samples.onRunSample (Samples.tsx:49)
I believe that the fix in microsoftgraph/msgraph-sdk-javascript#204 was incomplete. It only JSON-ifies the body if there's a Content-Type header, and in these error responses, it's absent.
AGS should be returning Content-Type on batch responses when there is one or more error responses in the batch. We need to follow up with AGS on this. @sriram-d Are you aware of this issue?
Thank you for reporting this issue. This appears to be an issue or limitation with the service APIs. Unfortunately, as the Microsoft Graph SDK team, we do not have ownership of the APIs that are causing you issues. We invite you to create a question about the service API to Microsoft Q&A and tagged with one of the [microsoft-graph-*] tags, that way it will get routed to the appropriate team for them to triage:
For now, we will close the issue on our side but feel free to open it in the relevant repository if you think the issue is specific to SDK.
Please let us know if this helps!
Note: We will close this repository on April 19, 2024.
Bug Report
Prerequisites
Description
When one or more requests in a batch fail, you cannot access the error from the body of the response.
Console Errors: [Is there any console error]
Screenshots: [If applicable, add screenshots to help explain your problem]
Steps to Reproduce
User.Read
.Calendars.ReadWrite
scope.Expected behavior: The error object in the body of the response (verified by Fiddler) should be returned.
Actual behavior: An error is logged to the console:
await newEventResponse.text()
returns[object Object]
.Additional Context
I believe that the fix in microsoftgraph/msgraph-sdk-javascript#204 was incomplete. It only JSON-ifies the body if there's a Content-Type header, and in these error responses, it's absent.
Relevant response from Fiddler trace:
Usage Information
SDK Version - 2.0.0
The text was updated successfully, but these errors were encountered: