diff --git a/library/src/containers/Error/Error.tsx b/library/src/containers/Error/Error.tsx
index d526a92d..c1dbe8e2 100644
--- a/library/src/containers/Error/Error.tsx
+++ b/library/src/containers/Error/Error.tsx
@@ -10,12 +10,11 @@ const renderErrors = (errors: ValidationError[]): React.ReactNode => {
return errors
.map((singleError: ValidationError, index: number) => {
- if (!singleError || !singleError.title || !singleError.location) {
+ if (!singleError) {
return null;
}
return (
-
{`${singleError.location.startLine}.`}
{singleError.title}
@@ -39,7 +38,7 @@ export const Error: React.FunctionComponent
= ({ error }) => {
-
+
{title ? `${ERROR_TEXT}: ${title}` : ERROR_TEXT}
{validationErrors && validationErrors.length ? (
diff --git a/library/src/helpers/parser.ts b/library/src/helpers/parser.ts
index a078bcef..ff997dce 100644
--- a/library/src/helpers/parser.ts
+++ b/library/src/helpers/parser.ts
@@ -3,7 +3,12 @@ import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';
import { ProtoBuffSchemaParser } from '@asyncapi/protobuf-schema-parser';
import { AvroSchemaParser } from '@asyncapi/avro-schema-parser';
-import { ErrorObject, ParserReturn, FetchingSchemaInterface } from '../types';
+import {
+ ErrorObject,
+ ParserReturn,
+ FetchingSchemaInterface,
+ ValidationError,
+} from '../types';
import { VALIDATION_ERRORS_TYPE } from '../constants';
@@ -18,8 +23,27 @@ export class Parser {
parserOptions?: any,
): Promise {
try {
- const { document } = await asyncapiParser.parse(content, parserOptions);
- return { asyncapi: document };
+ const parseResult = await asyncapiParser.parse(content, parserOptions);
+
+ let error: {
+ title: string | undefined;
+ validationErrors: ValidationError[] | undefined;
+ } = {
+ title: 'There were errors validating Asyncapi document',
+ validationErrors: undefined,
+ };
+
+ if (parseResult.document === undefined) {
+ parseResult.diagnostics.forEach(diagnostic => {
+ if (diagnostic.code.toString().includes('error')) {
+ const tempObj = { title: diagnostic.message };
+ error.validationErrors = [(tempObj as unknown) as ValidationError];
+ }
+ });
+ throw error;
+ }
+
+ return { asyncapi: parseResult.document };
} catch (err) {
return this.handleError(err as ErrorObject);
}