LoginSignup
0
1

More than 1 year has passed since last update.

40代おっさんGASでエラーメッセージをgoogle chatに送る

Posted at

本記事ついて

本記事は プログラミング初学者の私が学習していく中でわからない単語や概要をなるべくわかりやすい様にまとめたものです。
もし誤りなどありましたらコメントにてお知らせいただけるとありがたいです。

今回のコード

function chatFunction() {
    

    try {
      myFunction(); //前回作ったfunction
    } catch(error) {
      console.error(printError(error));
      
      const url = "google chatのwebhook";
      const message = {'text': printError(error)}
      const options = {
        'method': 'POST',
        'headers': {
          'Content-Type': 'application/json; charset=UTF-8'
        },
        'payload':JSON.stringify(message)
      };

      UrlFetchApp.fetch(url, options);
      
  }
}

function printError(error){
  return "[名前] " + error.name + "\n" +
         "[場所] " + error.fileName + "(" + error.lineNumber + "行目)\n" +
         "[メッセージ]" + error.message + "\n" +      
         "[StackTrace]\n" + error.stack;
}

作る必要性

今後、自分の作ったシステムを自動化すると自動で動いているときにエラーが発生する可能性があるため、チャットで通知することが必要と考えて作った!

0
1
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
1