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
Avoid trying to call JSON.stringify on HalResources
Oliver Güntherb07058364c3d
diff --git a/frontend/src/app/modules/hal/resources/error-resource.ts b/frontend/src/app/modules/hal/resources/error-resource.tsindex f7580ca1cc0..bd51cc3d722 100644--- a/frontend/src/app/modules/hal/resources/error-resource.ts+++ b/frontend/src/app/modules/hal/resources/error-resource.ts@@ -28,6 +28,7 @@import {HalResource} from 'core-app/modules/hal/resources/hal-resource';import {FormResource} from 'core-app/modules/hal/resources/form-resource';+import {HttpErrorResponse} from "@angular/common/http";export const v3ErrorIdentifierQueryInvalid = 'urn:openproject-org:api:v3:errors:InvalidQuery';export const v3ErrorIdentifierMultipleErrors = 'urn:openproject-org:api:v3:errors:MultipleErrors';@@ -38,8 +39,19 @@ export class ErrorResource extends HalResource {public details:any;public errorIdentifier:string;+ /** We may get a reference to the underlying http error */+ public httpError?:HttpErrorResponse;+public isValidationError:boolean = false;+ /**+ * Override toString to ensure the resource can+ * be printed nicely on console and in errors+ */+ public toString() {+ return `[ErrorResource ${this.message}]`;+ }+public get errorMessages():string[] {if (this.isMultiErrorMessage()) {return this.errors.map(error => error.message);diff --git a/frontend/src/app/modules/hal/resources/hal-resource.ts b/frontend/src/app/modules/hal/resources/hal-resource.tsindex a470acc0d73..bc5fb1379eb 100644--- a/frontend/src/app/modules/hal/resources/hal-resource.ts+++ b/frontend/src/app/modules/hal/resources/hal-resource.ts@@ -115,6 +115,18 @@ export class HalResource {this.halInitializer(this);}+ /**+ * Override toString to ensure the resource can+ * be printed nicely on console and in errors+ */+ public toString() {+ if (this.$href) {+ return `[HalResource href=${this.$href}]`;+ } else {+ return `[HalResource id=${this.id}]`;+ }+ }+/*** Returns the ID and ensures it's a string, null.* Returns a string when:diff --git a/frontend/src/app/modules/hal/services/hal-aware-error-handler.ts b/frontend/src/app/modules/hal/services/hal-aware-error-handler.tsindex 764e77384ca..ffae4855653 100644--- a/frontend/src/app/modules/hal/services/hal-aware-error-handler.ts+++ b/frontend/src/app/modules/hal/services/hal-aware-error-handler.ts@@ -6,7 +6,7 @@ import {HalResource} from "core-app/modules/hal/resources/hal-resource";@Injectable()export class HalAwareErrorHandler extends ErrorHandler {private text = {- internal_error: this.I18n.t('js.errors.internal')+ internal_error: this.I18n.t('js.error.internal')};constructor(private readonly I18n:I18nService) {diff --git a/frontend/src/app/modules/hal/services/hal-resource.service.ts b/frontend/src/app/modules/hal/services/hal-resource.service.tsindex 77b0db90eac..e512d54b9b1 100644--- a/frontend/src/app/modules/hal/services/hal-resource.service.ts+++ b/frontend/src/app/modules/hal/services/hal-resource.service.ts@@ -36,6 +36,8 @@ import {CollectionResource} from 'core-app/modules/hal/resources/collection-resoimport {HalLink, HalLinkInterface} from 'core-app/modules/hal/hal-link/hal-link';import {initializeHalProperties} from 'core-app/modules/hal/helpers/hal-resource-builder';import {URLParamsEncoder} from 'core-app/modules/hal/services/url-params-encoder';+import {ErrorReporter} from "core-app/sentry/sentry-reporter";+import {ErrorResource} from "core-app/modules/hal/resources/error-resource";export interface HalResourceFactoryConfigInterface {cls?:any;@@ -97,7 +99,9 @@ export class HalResourceService {map((response:any) => this.createHalResource(response)),catchError((error:HttpErrorResponse) => {console.error(`Failed to ${method} ${href}: ${error.name}`);- return throwError(this.createHalResource(error.error));+ const resource = this.createHalResource<ErrorResource>(error.error);+ resource.httpError = error;+ return throwError(resource);})) as any;}