Andrew
Andrew

Reputation: 21

How can I recovery from the error 9030 while mailbox.item.body.getAsync failed?

I'm working on the outlook add-in. But I get the issue that sometimes Office.context.mailbox.item.body.getAsync will failed when the add-in page reloaded. The worst thing is that, once body.getAsync return the error "APICallFailedDueToItemChange", the body.getAsync will be always failed with the same error. The detail of this error is {name: "APICallFailedDueToItemChange", message: "The selected item has been changed.", code: 9030}

I tried to recall the getAsync and even reload the whole window to make the add-in restarted, but the error will happen persistently. The only way is switching to another email.

Reproduce steps: 1. Create any outlook add in which try to get the email body 2. after add-in loaded, reload the add-in window 3. Once the 9030 error happened, those code in console will always trigger the same error until I switch to another email

await new Promise((resolve, reject) => {
    window.Office.context.mailbox.item.body.getAsync('text', (result) => {
      if (result.status === 'succeeded') {
        console.log(result.value)
        return resolve(result.value); // updated as suggested by Mavi Domates
      } else {
        console.error(result.error)
        return reject(result.error);
      }
    })
  })

I expect the getAsync should work fine even the previous callback is failed, but actual the exception will never be cleaned.

Upvotes: 2

Views: 422

Answers (1)

Mavi Domates
Mavi Domates

Reputation: 4521

Please modify your code as such, you aren't really doing anything with that promise.

await new Promise((resolve, reject) => {
    return window.Office.context.mailbox.item.body.getAsync('text', (result) => {
      if (result.status === 'succeeded') {
        console.log(result.value);
        return resolve(result.value);
      } else {
        console.error(result.error);
        return reject(result.error);
      }
    })
  })

Upvotes: 1

Related Questions