LoginSignup
0
0

More than 3 years have passed since last update.

【GAS x kintone連携】kintoneで発生したエラー処理は、ステータスコードで判別する

Last updated at Posted at 2020-09-19
  • 「GASのUrlFetchAppを使ってkintoneに何か処理をした際のエラー処理についてのメモ」改題。

Google Apps Script(GAS)からkintoneにレコード登録するなどの処理をした際、kintone側でエラーが発生した場合の、エラー処理のメモです。

kintone API エラー判別

kintone APIのエラー判別はレスポンスのステータスコードで判別する。

kintone REST API レスポンス
https://developer.cybozu.io/hc/ja/articles/201941754#step10

HTTPステータスコードが「200」であれば正常終了、それ以外はエラー終了です。

エラー処理

例えば、kintoneのレコード登録後にスプレッドシートを更新する場合のエラー処理は、下記の用にgetResponseCodeで判別する。

  // fetchRecordsはkintoneに何か処理をする関数
  fetchRecords(URL, option)
  .then(result => {
    if (result.getResponseCode() !== 200) { // ステータスコードが200以外の時
      throw new Error(result.getContentText()); // エラーをスローする
    }
    return result;
  })
  .then(result => {
    // スプレッドシートを更新する処理など
    console.log(result.getContentText());
  })
  .catch(error => {
    // エラー処理する
    console.error(error);
  });
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0