mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Also render violations (if present)
This commit is contained in:
@@ -18,6 +18,7 @@ class BackendErrorNotification extends React.Component<Props> {
|
|||||||
<div className="content">
|
<div className="content">
|
||||||
<p className="subtitle">{this.renderErrorName()}</p>
|
<p className="subtitle">{this.renderErrorName()}</p>
|
||||||
<p>{this.renderErrorDescription()}</p>
|
<p>{this.renderErrorDescription()}</p>
|
||||||
|
<p>{this.renderViolations()}</p>
|
||||||
{this.renderMetadata()}
|
{this.renderMetadata()}
|
||||||
</div>
|
</div>
|
||||||
</Notification>
|
</Notification>
|
||||||
@@ -42,6 +43,28 @@ class BackendErrorNotification extends React.Component<Props> {
|
|||||||
return translation;
|
return translation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderViolations = () => {
|
||||||
|
const { error, t } = this.props;
|
||||||
|
if (error.violations) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
<strong>{t("errors.violations")}</strong>
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
{error.violations.map((violation, index) => {
|
||||||
|
return (
|
||||||
|
<li key={index}>
|
||||||
|
<strong>{violation.path}:</strong> {violation.message}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
renderMetadata = () => {
|
renderMetadata = () => {
|
||||||
const { error, t } = this.props;
|
const { error, t } = this.props;
|
||||||
return (
|
return (
|
||||||
@@ -62,7 +85,8 @@ class BackendErrorNotification extends React.Component<Props> {
|
|||||||
|
|
||||||
renderContext = (error: BackendError) => {
|
renderContext = (error: BackendError) => {
|
||||||
if (error.context) {
|
if (error.context) {
|
||||||
return <>
|
return (
|
||||||
|
<>
|
||||||
<p>
|
<p>
|
||||||
<strong>{t("errors.context")}</strong>
|
<strong>{t("errors.context")}</strong>
|
||||||
</p>
|
</p>
|
||||||
@@ -75,11 +99,11 @@ class BackendErrorNotification extends React.Component<Props> {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
</>;
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
renderMoreInformationLink = (error: BackendError) => {
|
renderMoreInformationLink = (error: BackendError) => {
|
||||||
const { t } = this.props;
|
const { t } = this.props;
|
||||||
if (error.url) {
|
if (error.url) {
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
// @flow
|
// @flow
|
||||||
type Context = { type: string, id: string }[];
|
type Context = { type: string, id: string }[];
|
||||||
|
type Violation = { path: string, message: string };
|
||||||
|
|
||||||
export type BackendErrorContent = {
|
export type BackendErrorContent = {
|
||||||
transactionId: string,
|
transactionId: string,
|
||||||
errorCode: string,
|
errorCode: string,
|
||||||
message: string,
|
message: string,
|
||||||
url?: string,
|
url?: string,
|
||||||
context: Context
|
context: Context,
|
||||||
|
violations: Violation[]
|
||||||
};
|
};
|
||||||
|
|
||||||
export class BackendError extends Error {
|
export class BackendError extends Error {
|
||||||
@@ -15,6 +17,7 @@ export class BackendError extends Error {
|
|||||||
url: ?string;
|
url: ?string;
|
||||||
context: Context = [];
|
context: Context = [];
|
||||||
statusCode: number;
|
statusCode: number;
|
||||||
|
violations: Violation[];
|
||||||
|
|
||||||
constructor(content: BackendErrorContent, name: string, statusCode: number) {
|
constructor(content: BackendErrorContent, name: string, statusCode: number) {
|
||||||
super(content.message);
|
super(content.message);
|
||||||
@@ -24,6 +27,7 @@ export class BackendError extends Error {
|
|||||||
this.url = content.url;
|
this.url = content.url;
|
||||||
this.context = content.context;
|
this.context = content.context;
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
|
this.violations = content.violations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,5 +57,8 @@ export function createBackendError(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isBackendError(response: Response) {
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user