Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

typescript - How to fix when Thrown error object returns type: undefined in angular application?

I have a service class in my angular application written which catches error and throws it.

snippet from service class.ts

public getModulesSimpleMode(): Observable<any> {
return this.httpService.get<any>(
  this.apiService.getModulesSimpleModeEndPoint(this.preScanService.getPrescanJobId()),
).pipe(
  map(res => {
    let prevScanSummary: ScanSummary = null;
    if (res.body.previous_scan_summary) {
        const summary = res.body.previous_scan_summary;

        prevScanSummary = new ScanSummary(
                    summary.name,
                    summary.total_modules,
                    summary.scanned_modules,
                    summary.date_submitted,
                    summary.analysis_size,
                );
    }
    this.platformService.resetFilesChanged();
    if (res.body.all_modules) {
      this.totalModulesCount = res.body.all_modules.length;
    }

    this.selectedModulesSize = res.body.scan_size;

    return new ModuleSummary(res.body.all_modules, res.body.custom_selection,
      res.body.enable_module_selection, res.body.first_time_scanning,
      res.body.previous_selection, res.body.selected_module_ids,
      res.body.total_previously_selected_modules, res.body.total_supported_modules,
      res.body.total_unsupported_modules, res.body.total_veracode_default_modules,
      res.body.unselected_module_ids, res.body.unsupported_module_ids,
      res.body.veracode_default, res.body.estimate_delivery_date, res.body.build_id,
      res.body.build_date, res.body.upload_date, res.body.current_file_selection,
      prevScanSummary,res.body.scan_size
      );
  }), catchError(err => {
    //console.log("Error: "+err+" status:"+err.status)
    this.platformService.setModuleError(err.status);
    console.log("module error: "+this.platformService.getModuleErrors())
    return throwError(err);
  }));

}

I also have my component class where, in the else condition i am subscribing to the above mentioned method in the service class.

snippet from component.ts

updateSelectedModules() {
this.showSpinner("SPINNER_TEXT.SAVE_MODULE_SELECTION");

if (!this.moduleSelectionService.getSelectUnselectModuleStatus()) {
  this.moduleSelectionService.updateSelectUnselectModules(this.getModuleItems()).subscribe(response => {
    this.router.navigateByUrl(this.nextUrl);
   }
    , (error: any) => {
      // HTTP errors handling.
      this.globalErrorHandler.handleError(error);
      if (error.status !== 0) {
        this.statusWithHTTPErrors.push(error.status);
      } else {
        this.router.navigateByUrl(this.nextUrl);
      }
      this.httpErrorOnModules();
      this.activitySpinner.hideSpinner();
    });
} else {
  this.moduleSelectionService.getModulesSimpleMode().subscribe(response => {
    this.router.navigateByUrl(this.nextUrl);
   }
    , (error: any) => {
      // HTTP errors handling
      this.globalErrorHandler.handleError(error);
      if (error.status !== 0) {
        this.statusWithHTTPErrors.push(error.status);
        console.log("module selection error: "+error.status)
        console.log("Error Throw:"+error)
        return throwError(error)
      } else {
        this.router.navigateByUrl(this.nextUrl);
      }
      this.httpErrorOnModules();
      this.activitySpinner.hideSpinner();
    });
}

}

However in the component class, when i catch the error thrwon by the service class, i get the below error message. This is the same when i catch the error object. Any fix for this?

Error Throw:TypeError: this.moduleErrorStatus is undefined

question from:https://stackoverflow.com/questions/65898017/how-to-fix-when-thrown-error-object-returns-type-undefined-in-angular-applicati

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...