HISE Logo Forum
    • Categories
    • Register
    • Login

    Keep notification button hidden if there is a server error

    Scheduled Pinned Locked Moved General Questions
    3 Posts 2 Posters 126 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gorangroovesG
      gorangrooves
      last edited by

      I have a script to check my server for the latest version of the plugin. 👏

      If the version on the server (stored in a text file) is newer than the plugin in use, show a bell notification button. Once clicked, the button brings up a panel with text (pulled from the server) and prompts the user to click on a link to go to the website.

      If the plugin in use is current, the bell button should stay invisible.

      However, it seems that when there is some server error and the document is not fetched as it should, the bell button comes up anyway, and when clicked, the text says "undefined" in several places. 😳 Very embarrassing.

      How do I ensure that the bell button stays invisible if there is any fiasco with the server?

      Here is the error code I occasionally get (when there is a server issue, I assume). (I replaced the actual URL with a dummy URL)

      Interface: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>500 Internal Server Error</title>\n</head><body>\n<h1>Internal Server Error</h1>\n<p>The server encountered an internal error or\nmisconfiguration and was unable to complete\nyour request.</p>\n<p>Please contact the server administrator at \n [no address given] to inform them of the time this error occurred,\n and the actions you performed just before this error.</p>\n<p>More information about this error may be available\nin the server error log.</p>\n<p>Additionally, a 500 Internal Server Error\nerror was encountered while trying to use an ErrorDocument to handle the request.</p>\n<hr>\n<address>Apache Server at PluginUpdates.MyWebSite.com Port 443</address>\n</body></html>\n"
      
      Interface:! Line 263, column 30: API call with undefined parameter 1
      

      Here is the code:

      //-----------Notifications based on current version number-------
      
      const var VersionLabel = Content.getComponent("VersionLabel");
      reg versionNumber= Engine.getVersion(); //pull the current version# from the software
      VersionLabel.set("text", "v "+versionNumber); //display the current version on the interface
      
      reg vn= versionNumber.split('.');//Turn the current version number into an array;
      
      const var p = {
          "request": "version"
      };
      const var NotificationMessage = Content.getComponent("NotificationMessage");
      const var NotificationTitle = Content.getComponent("NotificationTitle");
      const var AboutVersion = Content.getComponent("AboutVersion");
      const var NewFeatures = Content.getComponent("NewFeatures");
      const var Prompt = Content.getComponent("Prompt");
      
      
      
      
      reg an;
      reg NotificationURL;
      Server.setBaseURL("https://PluginUpdates.MyWebSite.com");
      Server.callWithGET("/plugin_name_version", p, function(status, response)
      {
           
           an = response;
           Console.print(trace(response));
           if(isDefined(an)){
              
              //Setting variables from server information
              
              NotificationTitle.set("text", an["NotificationTitle"]);
              NotificationMessage.set("text", an["NotificationMessage"]);
              AboutVersion.set("text", "Your current version is "+versionNumber+" and the latest version is "+an["version"]);
              NewFeatures.set("text", an["NewFeatures"]);
              Prompt.set("text", an["Prompt"]);
              NotificationURL = an["NotificationURL"];
              var newVersion = an["version"].split('.');
              
              //Comparing versions
             if (newVersion[0] > vn[0] || (newVersion[0] == vn[0] && newVersion[1] > vn[1]) || (newVersion[0] == vn[0] && newVersion[1] == vn[1] && newVersion[2] > vn[2])){
                  UpdateButton.showControl(true); 
             }
          }
      });
      

      Goran Rista
      https://gorangrooves.com

      Handy Drums and Handy Grooves
      https://library.gorangrooves.com

      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @gorangrooves
        last edited by

        @gorangrooves That's what the status parameter is for. If the server messes up, it will return a HTTP error code that you can handle, otherwise it's 200 (OK).

        gorangroovesG 1 Reply Last reply Reply Quote 1
        • gorangroovesG
          gorangrooves @Christoph Hart
          last edited by

          @Christoph-Hart Makes sense. I'll try to work that out tomorrow. Thanks very much!

          Goran Rista
          https://gorangrooves.com

          Handy Drums and Handy Grooves
          https://library.gorangrooves.com

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          43

          Online

          1.7k

          Users

          11.7k

          Topics

          101.9k

          Posts