Skip to content

Commit 383378a

Browse files
authored
Merge pull request #365 from mulesoft/bugs/console-loader-error-handling
Handler raml parser 1.0 errors properly on raml-console-loader directive
2 parents 6a6b445 + 022220e commit 383378a

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

dist/scripts/api-console.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,18 +1163,14 @@
11631163
$scope.vm.error = void(0);
11641164

11651165
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
1166-
$scope.vm.error = {buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
1166+
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
11671167
} else {
11681168
return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options)
11691169
.then(function (raml) {
11701170
$scope.vm.raml = raml;
11711171
})
11721172
.catch(function (error) {
1173-
$scope.vm.error = angular.extend(error, {
1174-
/*jshint camelcase: false */
1175-
buffer: (error.context_mark || error.problem_mark).buffer
1176-
/*jshint camelcase: true */
1177-
});
1173+
$scope.vm.error = error;
11781174
})
11791175
.finally(function () {
11801176
$scope.vm.loaded = true;
@@ -6979,17 +6975,12 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
69796975
" </header>\n" +
69806976
"\n" +
69816977
" <div class=\"raml-console-initializer-row\">\n" +
6982-
" <p class=\"raml-console-initializer-input-container\" style=\"height: 550px;\">\n" +
6983-
" <textarea id=\"raml\" ui-codemirror=\"{\n" +
6984-
" gutters: ['CodeMirror-lint-markers'],\n" +
6985-
" lineNumbers: true,\n" +
6986-
" lineWrapping: false,\n" +
6987-
" lint: true,\n" +
6988-
" mode: 'yaml',\n" +
6989-
" tabSize: 2,\n" +
6990-
" theme: 'raml-console'\n" +
6991-
" }\" ng-model=\"vm.error.buffer\"></textarea>\n" +
6992-
" </p>\n" +
6978+
" <div class=\"raml-console-parser-error\">\n" +
6979+
" <span>{{ vm.error.message }}</span>\n" +
6980+
" </div>\n" +
6981+
" <div class=\"raml-console-error-pre\" ng-repeat=\"err in vm.error.parserErrors\">\n" +
6982+
" {{err.message}}\n" +
6983+
" </div>\n" +
69936984
" </div>\n" +
69946985
" </section>\n" +
69956986
" </div>\n" +

src/app/directives/raml-console-loader.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@
4141
$scope.vm.error = void(0);
4242

4343
if(RAML.LoaderUtils.ramlOriginValidate(url, $scope.options)) {
44-
$scope.vm.error = {buffer : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
44+
$scope.vm.error = {message : 'RAML origin check failed. Raml does not reside underneath the path:' + RAML.LoaderUtils.allowedRamlOrigin($scope.options)};
4545
} else {
4646
return ramlParser.loadPath($window.resolveUrl(url), null, $scope.options)
4747
.then(function (raml) {
4848
$scope.vm.raml = raml;
4949
})
5050
.catch(function (error) {
51-
$scope.vm.error = angular.extend(error, {
52-
/*jshint camelcase: false */
53-
buffer: (error.context_mark || error.problem_mark).buffer
54-
/*jshint camelcase: true */
55-
});
51+
$scope.vm.error = error;
5652
})
5753
.finally(function () {
5854
$scope.vm.loaded = true;

src/app/directives/raml-console-loader.tpl.html

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ <h4 class="raml-console-initializer-subhead">Error while parsing</h4>
1313
</header>
1414

1515
<div class="raml-console-initializer-row">
16-
<p class="raml-console-initializer-input-container" style="height: 550px;">
17-
<textarea id="raml" ui-codemirror="{
18-
gutters: ['CodeMirror-lint-markers'],
19-
lineNumbers: true,
20-
lineWrapping: false,
21-
lint: true,
22-
mode: 'yaml',
23-
tabSize: 2,
24-
theme: 'raml-console'
25-
}" ng-model="vm.error.buffer"></textarea>
26-
</p>
16+
<div class="raml-console-parser-error">
17+
<span>{{ vm.error.message }}</span>
18+
</div>
19+
<div class="raml-console-error-pre" ng-repeat="err in vm.error.parserErrors">
20+
{{err.message}}
21+
</div>
2722
</div>
2823
</section>
2924
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>API Console</title>
7+
<link href="styles/api-console-light-theme.css" rel="stylesheet" class="theme">
8+
</head>
9+
<body ng-app="ramlConsoleApp" ng-cloak class="raml-console-body">
10+
<raml-console-loader src="raml/wrong.raml"></raml-console-loader>
11+
<script src="scripts/api-console-vendor.js"></script>
12+
<script src="scripts/api-console.js"></script>
13+
<script type="text/javascript">
14+
$.noConflict();
15+
</script>
16+
</body>
17+
</html>

test/regression/page_objects/errorPO.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var basePO = require('./basePO');
44

55
function ErrorPO () {
66
this.title = element(by.css('.raml-console-heading'));
7-
this.errorMessage = element(by.css('.raml-console-error-message'));
7+
this.errorMessage = element(by.css('.raml-console-parser-error'));
88
this.errorSnippet = element(by.css('.raml-console-error-snippet'));
99

1010
this.getTitle = function () {

test/regression/standalone/directiveSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ var assertions = require('../assertions');
44
var factory = require('../page_objects');
55

66
module.exports = function() {
7+
8+
it('should be able to diplay errors for wrong raml', function () {
9+
// Arrange
10+
var assert = assertions.create('error');
11+
12+
// Act
13+
browser.get('http://localhost:9000/directive-wrong.html');
14+
15+
// Assert
16+
assert.ifErrorMessageIsPresent('Api contains errors.');
17+
});
18+
719
it('should be able to diplay the API title', function () {
820
// Arrange
921
var assert = assertions.create('resource');

0 commit comments

Comments
 (0)