我想知道從服務(wù)器(Spring Boot)檢索消息并在前端(Vue JS、ES6)中顯示的最佳方法是什么。后端(這是我唯一成功的方法,在標(biāo)頭中傳遞錯(cuò)誤消息,但也許有更好的解決方案?):public ResponseEntity<?> getOneReport(@PathVariable Long incidentId) {... HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.TEXT_PLAIN); header.set("text", "My custom error message"); return ResponseEntity.notFound() .headers(header) .build();前端:axios.get(...).then(...).catch((error) => { console.log(error.headers.text);我試圖將我的自定義錯(cuò)誤消息從服務(wù)傳遞到客戶端,如下所示:return new ResponseEntity<Object>( "My custom error message that I want to display in frontend", new HttpHeaders(), HttpStatus.FORBIDDEN);但我不知道如何從我的客戶端(ES6/Vue js)讀取該消息:.catch((error) => { console.log(error.error);或者.catch((error) => { console.log(error.response.data); -> I get Blob {size: 59, type: "text/plain"}
ResponseEntity 和 JavaScript - 如何檢索自定義錯(cuò)誤消息
繁星點(diǎn)點(diǎn)滴滴
2021-11-04 15:34:59