1+ const axios = require ( 'axios' )
12const { Base64 } = require ( 'js-base64' )
23const debounce = require ( 'debounce' )
34const semver = require ( 'semver' )
@@ -10,9 +11,6 @@ const {
1011 annotateChanges,
1112} = require ( './directives' )
1213
13- const fetch = ( ...args ) =>
14- import ( 'node-fetch' ) . then ( ( { default : fetch } ) => fetch ( ...args ) )
15-
1614module . exports = function ( RED ) {
1715 function ConnectionNode ( config ) {
1816 RED . nodes . createNode ( this , config )
@@ -580,27 +578,30 @@ module.exports = function (RED) {
580578 }
581579
582580 this . checkVersion = async function ( ) {
583- const response = await fetch (
584- `${
585- config . backendUrl
586- } /check_version?version=${ VSH_VERSION } &nr_version=${ RED . version ( ) } &thingId=${
587- this . credentials . thingId
588- } `
589- )
581+ let response
590582
591- // EXAMPLE
592- // {
593- // "isAllowedVersion": false,
594- // "isLatestVersion": false,
595- // "updateHint": "Please update to the latest version of VSH!",
596- // "allowedDeviceCount": 5,
597- // }
598- if ( ! response . ok ) {
583+ try {
584+ response = await axios . get (
585+ `${
586+ config . backendUrl
587+ } /check_version?version=${ VSH_VERSION } &nr_version=${ RED . version ( ) } &thingId=${
588+ this . credentials . thingId
589+ } `
590+ )
591+
592+ // EXAMPLE response.data
593+ // {
594+ // "isAllowedVersion": false,
595+ // "isLatestVersion": false,
596+ // "updateHint": "Please update to the latest version of VSH!",
597+ // "allowedDeviceCount": 5,
598+ // }
599+ return response . data
600+ } catch ( error ) {
599601 throw new Error (
600602 `HTTP Error Response: ${ response . status } ${ response . statusText } `
601603 )
602604 }
603- return await response . json ( )
604605 }
605606
606607 this . disableUnallowedDevices = function ( allowedDeviceCount ) {
0 commit comments