diff --git a/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js b/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js index 4d36495dd3..63eb36c130 100644 --- a/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js +++ b/scm-ui-components/packages/ui-components/src/BackendErrorNotification.js @@ -18,6 +18,7 @@ class BackendErrorNotification extends React.Component {

{this.renderErrorName()}

{this.renderErrorDescription()}

+

{this.renderViolations()}

{this.renderMetadata()}
@@ -42,6 +43,28 @@ class BackendErrorNotification extends React.Component { return translation; }; + renderViolations = () => { + const { error, t } = this.props; + if (error.violations) { + return ( + <> +

+ {t("errors.violations")} +

+ + + ); + } + }; + renderMetadata = () => { const { error, t } = this.props; return ( @@ -62,24 +85,25 @@ class BackendErrorNotification extends React.Component { renderContext = (error: BackendError) => { if (error.context) { - return <> -

- {t("errors.context")} -

-
    - {error.context.map((context, index) => { - return ( -
  • - {context.type}: {context.id} -
  • - ); - })} -
- ; + return ( + <> +

+ {t("errors.context")} +

+
    + {error.context.map((context, index) => { + return ( +
  • + {context.type}: {context.id} +
  • + ); + })} +
+ + ); } }; - renderMoreInformationLink = (error: BackendError) => { const { t } = this.props; if (error.url) { diff --git a/scm-ui-components/packages/ui-components/src/errors.js b/scm-ui-components/packages/ui-components/src/errors.js index 9b278c7ddd..de425109b4 100644 --- a/scm-ui-components/packages/ui-components/src/errors.js +++ b/scm-ui-components/packages/ui-components/src/errors.js @@ -1,12 +1,14 @@ // @flow type Context = { type: string, id: string }[]; +type Violation = { path: string, message: string }; export type BackendErrorContent = { transactionId: string, errorCode: string, message: string, url?: string, - context: Context + context: Context, + violations: Violation[] }; export class BackendError extends Error { @@ -15,6 +17,7 @@ export class BackendError extends Error { url: ?string; context: Context = []; statusCode: number; + violations: Violation[]; constructor(content: BackendErrorContent, name: string, statusCode: number) { super(content.message); @@ -24,6 +27,7 @@ export class BackendError extends Error { this.url = content.url; this.context = content.context; this.statusCode = statusCode; + this.violations = content.violations; } } @@ -53,5 +57,8 @@ export function createBackendError( } export function isBackendError(response: Response) { - return response.headers.get("Content-Type") === "application/vnd.scmm-error+json;v=2"; + return ( + response.headers.get("Content-Type") === + "application/vnd.scmm-error+json;v=2" + ); }