public openTranscript()

in packages/app/main/src/protocolHandler.ts [197:236]


  public openTranscript(protocol: Protocol): void {
    const { url } = protocol.parsedArgs;
    const options = { url };

    return got(options)
      .then(res => {
        if (/^2\d\d$/.test(res.statusCode)) {
          if (res.body) {
            try {
              // parse the activities from the downloaded transcript
              const transcriptString = res.body;
              const activities = JSON.parse(transcriptString);
              if (!Array.isArray(activities)) {
                throw new Error('Invalid transcript file contents; should be an array of conversation activities.');
              }
              const { name, ext } = Path.parse(url);
              const filename = `${name}${ext}`;
              store.dispatch(openTranscript(filename, activities));
            } catch (e) {
              throw new Error(`Error occured while reading downloaded transcript: ${e}`);
            }
          }
        } else {
          if (res.statusCode === 401) {
            // auth failed
            const stat = res.body || res.statusText || '';
            throw new Error(`Authorization error while trying to download transcript: ${stat}`);
          }
          if (res.statusCode === 404) {
            // transcript link is broken / doesn't exist anymore
            throw new Error(`Transcript file not found at: ${url}`);
          }
        }
      })
      .catch(err => {
        const errMsg = `Error downloading and parsing transcript file: ${err}`;
        const notification = newNotification(errMsg);
        sendNotificationToClient(notification, this.commandService);
      });
  }