Skip to content

Commit

Permalink
Fixes #76 Generator errors not displayed in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont committed Mar 11, 2019
1 parent 366ff8a commit 855fb6d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 32 deletions.
12 changes: 5 additions & 7 deletions .github/ISSUE_TEMPLATE.md
@@ -1,14 +1,12 @@
### Version

* vert.x starter:

### Context

I encountered an exception which looks suspicious while ...
The starter failed to create my project with following settings...

or

### Do you have a reproducer?
The generated project fails to build...

* Link to github project/gist
...etc

### Steps to reproduce

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/vertx/starter/web/util/RestUtil.java
Expand Up @@ -16,6 +16,7 @@

package io.vertx.starter.web.util;

import io.vertx.core.http.HttpHeaders;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -30,7 +31,9 @@ public static void error(RoutingContext rc, Throwable cause) {
}

public static void error(RoutingContext rc, String message) {
rc.response().setStatusCode(HTTP_INTERNAL_ERROR).end(new JsonObject().put("status", HTTP_INTERNAL_ERROR).put("message", message).toString());
rc.response().setStatusCode(HTTP_INTERNAL_ERROR)
.putHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.end(new JsonObject().put("status", HTTP_INTERNAL_ERROR).put("message", message).toBuffer());
}

private static void respond(RoutingContext rc, String contentType, String chunk) {
Expand Down
8 changes: 3 additions & 5 deletions src/main/resources/webroot/index.html
Expand Up @@ -244,11 +244,10 @@ <h2>Generate a Vert.x project </h2>
</div>
</div>
<div class="row">
<div uib-alert ng-repeat="alert in vm.alerts" class="alert-danger" close="vm.closeAlert($index)">
{{alert}}
<div uib-alert ng-repeat="alert in vm.alerts track by $index" class="alert-danger" close="vm.closeAlert($index)">
<p>
<a ng-href="https://github.com/vert-x3/vertx-starter/issues/new?title={{alert}}&body={{vm.vertxProject}}">Report
the problem.</a>
{{alert}}. Please <a target="_blank" ng-href="https://github.com/vert-x3/vertx-starter/issues/new">report</a> an
issue.
</p>
</div>
<div class="col-sm-12">
Expand Down Expand Up @@ -336,7 +335,6 @@ <h2>Generate a Vert.x project </h2>
</div>
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"
integrity="sha256-3SrLjPeRPa1ofM280r+OMcUjJZKLWJHr6SRtRu3dRb0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-resource/1.6.1/angular-resource.min.js"
Expand Down
30 changes: 11 additions & 19 deletions src/main/resources/webroot/main.js
Expand Up @@ -39,29 +39,16 @@ angular

return service;
}])
.factory('httpErrorInterceptor', ['$q', function ($q) {
return {
'responseError': function (rejection) {
if (rejection.status === 500) {
var errorData = rejection.data;
var decoder = new TextDecoder("utf-8");
rejection.data = JSON.parse(decoder.decode(errorData.data));
}
return $q.reject(rejection);
}
}
}])
.filter('capitalize', function () {
return function (input) {
return (!!input) ? input.charAt(0).toUpperCase() + input.slice(1).toLowerCase() : '';
}
})
.config(['$httpProvider', 'hotkeysProvider', function ($httpProvider, hotkeysProvider) {
.config(['hotkeysProvider', function (hotkeysProvider) {
hotkeysProvider.includeCheatSheet = false;
$httpProvider.interceptors.push('httpErrorInterceptor');
}])
.controller('VertxStarterController', ['$document', '$window', 'hotkeys', 'Starter',
function VertxStarterController($document, $window, hotkeys, Starter) {
.controller('VertxStarterController', ['$scope', '$document', '$window', 'hotkeys', 'Starter',
function VertxStarterController($scope, $document, $window, hotkeys, Starter) {
var vm = this;
vm.isGenerating = false;
vm.vertxVersions = [];
Expand Down Expand Up @@ -157,7 +144,6 @@ angular
function save(data, contentType) {
if (vm.isFileSaverSupported) {
var archive = new Blob([data], {type: contentType});
console.log(archive.size);
saveAs(archive, vm.vertxProject.artifactId + '.' + vm.vertxProject.archiveFormat);
}
}
Expand All @@ -170,7 +156,6 @@ angular
return dependency.artifactId;
});
vertxProject.vertxDependencies = artifacts.join();
console.log(JSON.stringify(vertxProject));
return vertxProject;
}

Expand All @@ -185,7 +170,14 @@ angular
})
.catch(function (error) {
vm.isGenerating = false;
addAlert(error.data.message);
var reader = new FileReader();
reader.addEventListener("loadend", function () {
var message = JSON.parse(reader.result).message;
$scope.$apply(function () {
$scope.vm.addAlert(message);
});
});
reader.readAsText(error.data, "utf8");
});
}

Expand Down

0 comments on commit 855fb6d

Please sign in to comment.