2

There is a simple code excerpt:

gapi.client.sheets.spreadsheets.values.get({
    spreadsheetId,
    range: "TOP!A:B"
}).then(result => {
       doSomething()
})

How to detect and handle errors if they occur?

Errors like 503,403 etc. that are appear in response data:

{error:...}

1 Answer 1

1

For example, how about this modification?

Modified script:

gapi.client.sheets.spreadsheets.values.get({
    spreadsheetId,
    range: "TOP!A:B"
}).then(result => {
       doSomething()
}, (error) => { // Added
    if (error.status == 403) { // You can also use switch().
      console.log('Status code is 403. Message: %s', error.result.error.message);
    } else if (error.status == 503) {
      console.log('Status code is 503. Message: %s', error.result.error.message);
    }
})

Reference:

If this was not what you want, I'm sorry.

Sign up to request clarification or add additional context in comments.

2 Comments

Wonderful! Thank you very much!
@Max S Thank you for your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.