Я пытаюсь написать свой первый сервис в приложении JHipster. Итак, у меня есть компонент с этим вызовом
this.saisonsService.getActiveSaison().subscribe((resultat: HttpResponse<ISaisons>) => {
const existSaison = resultat.body;
//TO DO
}
}, error => {
// TO DO
});
А служба с
getActiveSaison(): Observable<EntityResponseType> {
return this.http.get<ISaisons>(`${this.resourceUrlActiveSaison}`, { observe: 'response' });
}
В бэкенде служба в порядке :
@GetMapping("/saisonActive")
public ResponseEntity<Saisons> getActiveSaison() {
log.debug("REST request to get active Saison");
Optional<Saisons> saisonActive = saisonsService.getActiveSaison();
return ResponseUtil.wrapOrNotFound(saisonActive);
}
Но когда я вызываю его, у меня возникает эта ошибка
{
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "http://localhost:9000/api/activeSaison",
"ok": false,
"name": "HttpErrorResponse",
"message": "Http failure during parsing for http://localhost:9000/api/activeSaison",
"error": {
"error": {},
"text": "<!DOCTYPE html>\r\n<html class=\"no-js\" lang=\"fr\" dir=\"ltr\">\r\n <head>\r\n <meta charset=\"utf-8\" />\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\r\n <title>pdf4pweb</title>\r\n <meta name=\"description\" content=\"Description for pdf4pweb\" />\r\n <meta name=\"google\" content=\"notranslate\" />\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\" />\r\n <meta name=\"theme-color\" content=\"#000000\" />\r\n <base href=\"/\" />\r\n <link rel=\"icon\" href=\"favicon.ico\" />\r\n <link rel=\"manifest\" href=\"manifest.webapp\" />\r\n <link rel=\"stylesheet\" href=\"content/css/loading.css\" />\r\n <!-- jhipster-needle-add-resources-to-root - JHipster will add new resources here -->\r\n </head>\r\n <body>\r\n <!--[if lt IE 9]>\r\n <p class=\"browserupgrade\">\r\n You are using an <strong>outdated</strong> browser. Please <a href=\"http://browsehappy.com/\">upgrade your browser</a> to improve\r\n your experience.\r\n </p>\r\n <![endif]-->\r\n <jhi-main>\r\n <div class=\"app-loading\">\r\n <div class=\"lds-pacman\">\r\n <div>\r\n <div></div>\r\n <div></div>\r\n <div></div>\r\n </div>\r\n <div>\r\n <div></div>\r\n <div></div>\r\n <div></div>\r\n </div>\r\n </div>\r\n </div>\r\n <div class=\"app-loading\">\r\n <div id=\"jhipster-error\" style=\"display: none\">\r\n <!-- This content is for troubleshooting purpose and will be removed when app renders -->\r\n <h1>An error has occurred :-(</h1>\r\n <h2>Usual error causes</h2>\r\n <ol>\r\n <li>\r\n You started the application from an IDE and you didn't run <code style=\"color: red\">npm start</code> or\r\n <code style=\"color: red\">npm run webapp:build</code>.\r\n </li>\r\n <li>\r\n You had a network error while running <code style=\"color: red\">npm install</code>. If you are behind a corporate proxy, it is\r\n likely that this error was caused by your proxy. Have a look at the JHipster error logs, you will probably have the cause of\r\n the error.\r\n </li>\r\n <li>\r\n You installed a Node.js version that doesn't work with JHipster: please use an LTS (long-term support) version, as it's the\r\n only version we support.\r\n </li>\r\n </ol>\r\n <h2>Building the client side code again</h2>\r\n <p>If you want to go fast, run <code style=\"color: red\">./mvnw</code> to build and run everything.</p>\r\n <p>If you want to have more control, so you can debug your issue more easily, you should follow the following steps:</p>\r\n <ol>\r\n <li>Install npm dependencies with the command <code style=\"color: red\">npm install</code></li>\r\n <li>\r\n Build the client with the command <code style=\"color: red\">npm run webapp:build</code> or\r\n <code style=\"color: red\">npm start</code>\r\n </li>\r\n <li>Start the server with <code style=\"color: red\">./mvnw</code> or using your IDE</li>\r\n </ol>\r\n\r\n <h2>Getting more help</h2>\r\n\r\n <h3>If you have a question on how to use JHipster</h3>\r\n <p>\r\n Go to Stack Overflow with the\r\n <a href=\"http://coderhelper.com/tags/jhipster\" target=\"_blank\" rel=\"noopener noreferrer\">\"jhipster\"</a> tag.\r\n </p>\r\n\r\n <h3>If you have a bug or a feature request</h3>\r\n <p>\r\n First read our\r\n <a href=\"https://github.com/jhipster/generator-jhipster/blob/main/CONTRIBUTING.md\" target=\"_blank\" rel=\"noopener noreferrer\"\r\n >contributing guidelines</a\r\n >.\r\n </p>\r\n <p>\r\n Then, fill a ticket on our\r\n <a href=\"https://github.com/jhipster/generator-jhipster/issues/new/choose\" target=\"_blank\" rel=\"noopener noreferrer\"\r\n >bug tracker</a\r\n > we'll be happy to resolve your issue!\r\n </p>\r\n\r\n <h3>If you want to chat with contributors and other users</h3>\r\n <p>\r\n Join our chat room on\r\n <a href=\"https://gitter.im/jhipster/generator-jhipster\" target=\"_blank\" rel=\"noopener noreferrer\">Gitter.im</a>. Please note\r\n that this is a public chat room, and that we expect you to respect other people and write in a correct English language!\r\n </p>\r\n <!-- end of troubleshooting content -->\r\n </div>\r\n </div>\r\n </jhi-main>\r\n <noscript>\r\n <h1>You must enable JavaScript to view this page.</h1>\r\n </noscript>\r\n <script type=\"text/javascript\">\r\n // show an error message if the app loading takes more than 4 sec\r\n window.onload = function () {\r\n setTimeout(showError, 4000);\r\n };\r\n function showError() {\r\n var errorElm = document.getElementById('jhipster-error');\r\n if (errorElm && errorElm.style) {\r\n errorElm.style.display = 'block';\r\n }\r\n }\r\n </script>\r\n <!-- Google Analytics: uncomment and change UA-XXXXX-X to be your site's ID.\r\n <script>\r\n (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=\r\n function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;\r\n e=o.createElement(i);r=o.getElementsByTagName(i)[0];\r\n e.src='//www.google-analytics.com/analytics.js';\r\n r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));\r\n ga('create','UA-XXXXX-X');ga('send','pageview');\r\n </script>-->\r\n </body>\r\n</html>\r\n"
}
}
Я не понимаю, почему этот код не работает... Есть идеи?
Вы уверены, что получаете JSON? Мне кажется, что вы получаете HTML (см. свойство «текст»), вы проверили ответ в инструментах разработчика Chrome? Я полагаю, что это для Angular?
Конечно, это Angular с JHipster. Проблема в том, что я ничего не отправляю (без параметров), а http-запрос никогда не отправляется обратно (я думаю, что создание запроса не удалось). Но я не знаю, почему это текст, а не JSON
Вы проверили, что заголовки ваших запросов содержат правильный MIME-тип? Из того, что вы говорите, мне непонятно, проверяли ли вы запрос/ответ на вкладке сети инструментов разработчика браузера. Не могли бы вы сделать это и вставить req/resp в свой вопрос? Если бы запрос не был отправлен на бэкенд, вы бы не получили html.
Я не знаю почему, но чистый/рестант решил эту проблему.