OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add handling and spec in case of job status returning 404
Oliver Güntherab192c071937
diff --git a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.tsindex 538865f6bc2..c3644cdd6c0 100644--- a/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts+++ b/frontend/src/app/modules/job-status/job-status-modal/job-status.modal.ts@@ -3,7 +3,7 @@ import {OpModalLocalsMap} from 'core-components/op-modals/op-modal.types';import {OpModalComponent} from 'core-components/op-modals/op-modal.component';import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {OpModalLocalsToken} from "core-components/op-modals/op-modal.service";-import {HttpClient} from '@angular/common/http';+import {HttpClient, HttpErrorResponse, HttpResponse} from '@angular/common/http';import {interval, Observable, timer} from "rxjs";import {map, switchMap, takeUntil, takeWhile} from "rxjs/operators";import {@@ -77,12 +77,12 @@ export class JobStatusModal extends OpModalComponent implements OnInit {timer(0, 2000).pipe(switchMap(() => this.performRequest()),- takeWhile(response => this.continuedStatus(response), true),+ takeWhile(response => !!response.body && this.continuedStatus(response.body), true),this.untilDestroyed(),withDelayedLoadingIndicator(this.loadingIndicator.getter('modal')),).subscribe(- object => this.onResponse(object),- error => this.handleError(error.message),+ response => this.onResponse(response),+ error => this.handleError(error),() => this.isLoading = false);}@@ -110,15 +110,21 @@ export class JobStatusModal extends OpModalComponent implements OnInit {return ['in_queue', 'in_process'].includes(response.status);}- private onResponse(response:JobStatusInterface) {- let status = this.status = response.status;+ private onResponse(response:HttpResponse<JobStatusInterface>) {+ let body = response.body;- this.message = response.message ||+ if (!body) {+ throw new Error(response as any);+ }++ let status = this.status = body.status;++ this.message = body.message ||this.I18n.t(`js.job_status.generic_messages.${status}`, { defaultValue: status });- if (response.payload) {- this.handleRedirect(response.payload?.redirect);- this.handleDownload(response.payload?.download);+ if (body.payload) {+ this.handleRedirect(body.payload?.redirect);+ this.handleDownload(body.payload?.download);}this.statusIcon = this.iconForStatus();@@ -140,17 +146,26 @@ export class JobStatusModal extends OpModalComponent implements OnInit {}}- private performRequest():Observable<JobStatusInterface> {+ private performRequest():Observable<HttpResponse<JobStatusInterface>> {return this.httpClient.get<JobStatusInterface>(this.jobUrl,- { observe: 'body', responseType: 'json' }+ { observe: 'response', responseType: 'json' });}- private handleError(error:string|null|undefined) {- this.notifications.addError(error || this.I18n.t('js.error.internal'));+ private handleError(error:HttpErrorResponse) {+ if (error?.status === 404) {+ this.statusIcon = 'icon-help';+ this.message = this.I18n.t('js.job_status.generic_messages.not_found');+ return;+ }+++ this.statusIcon = 'icon-error';+ this.message = error?.message || this.I18n.t('js.error.internal');+ this.notifications.addError(this.message);}private get jobUrl():string {diff --git a/modules/job_status/config/locales/js-en.yml b/modules/job_status/config/locales/js-en.ymlindex 1c42f6754f8..f299b3dee3a 100644--- a/modules/job_status/config/locales/js-en.yml+++ b/modules/job_status/config/locales/js-en.yml@@ -6,6 +6,7 @@ en:title: 'Background job status'redirect: 'You are being redirected.'generic_messages:+ not_found: 'This job could (no longer) be found.'in_queue: 'The job has been queued and will be processed shortly.'in_process: 'The job is currently being processed.'error: 'The job has failed to complete.'diff --git a/modules/job_status/config/routes.rb b/modules/job_status/config/routes.rbindex 00f4b55f3ca..30626a7a021 100644--- a/modules/job_status/config/routes.rb+++ b/modules/job_status/config/routes.rb@@ -1,3 +1,5 @@OpenProject::Application.routes.draw do- get '/job_statuses/:job_uuid', to: 'angular#empty_layout'+ get '/job_statuses/:job_uuid',+ to: 'angular#empty_layout',+ as: 'job_status'enddiff --git a/modules/job_status/spec/features/job_status_spec.rb b/modules/job_status/spec/features/job_status_spec.rbnew file mode 100644index 00000000000..8e662bd64a8--- /dev/null+++ b/modules/job_status/spec/features/job_status_spec.rb@@ -0,0 +1,44 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe 'Job status', type: :feature, js: true do+ using_shared_fixtures :admin++ before do+ login_as admin+ end++ it 'renders a descriptive error in case of 404' do+ visit '/job_statuses/something-that-does-not-exist'++ expect(page).to have_selector('.icon-big.icon-help', wait: 10)+ expect(page).to have_content 'This job could (no longer) be found.'+ end+end