Thursday 19 August 2021

Error handler not being reached for gulp task

I am uploading and deploying sharepoint packages via gulp. Sometimes, it's possible that the app catalog folder doesn't exist, and so the upload will fail. I'd like to just make a note of the error and move on. I've tried to add some error handling to my code but i can't seem to catch it. I've tried inside the pipe, outside, and also a try / catch just after the for loop.

Error

Uploading packge to widget catalog...
[14:29:40] Uploading test.sppkg
[14:29:40] INFO: Folder 'AppCatalog' doesn't exist and will be created
[14:29:40] ERROR: StatusCodeError: 403 - {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied."}}}

Gulp Code

const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
const spsync = require('gulp-spsync-creds').sync;
const sppkgDeploy = require('node-sppkg-deploy');


for (const site of sites) {
   console.log("Uploading packge to " + site + " catalog...");
       await new Promise((resolve, reject) => {
          gulp
          .src(folderLocation)
          .pipe(
            spsync({
              username: uname,
              password: pwd,
              site: siteUrl + "/" + site,
              libraryPath: catalogName,
              publish: true,
            })
          )
          .on("finish",() => {
            console.log("Completed upload of:" + name + ". Starting deploy... ");
              sppkgDeploy.deploy({
                username: uname,
                password: pwd,
                absoluteUrl: siteUrl + "/" + site,
                filename: name,
                skipFeatureDeployment: true,
                verbose: false
            });
            resolve();
          })
          .on("error", (e)=>{
            console.log("%%%%%%%%%%FAILED!")
          });
        });
      }

Ultimately, I'd like to catch error number 403 ... and just do a simple console.log and move on. Can someone tell me where I've gone wrong? I'm presently researching gulp plumber(?) in case that's relevant. But this is my first gulp script so .. just checking with the community in case I've gone astray somewhere.

thanks.

EDIT 1

Updated my code so it looks like this:

      await new Promise((resolve, reject) => {
          gulp
          .src(folderLocation)
          .pipe(
            spsync({
              username: uname,
              password: pwd,
              site: siteCatalogUrl + "/",
              libraryPath: catalogName,
              publish: true,
            }).on("error", e => console.log("==@@@@@@@@THIS HAS BOMBED@@@@@@@@@@@@@@")))
          .on("finish",resolve); 
          });

Basically just added error handler for the spsync. But the code never hits there either.



from Error handler not being reached for gulp task

No comments:

Post a Comment