如何在react中显示sqlexception消息?

ercv8c1e  于 2021-07-29  发布在  Java
关注(0)|答案(0)|浏览(266)

我有一个React前端,java后端和oracle数据库。我有一个触发器(在删除之前),如果我删除了一个“错误”的条目,它会引发一个自定义异常。我希望此消息显示在react中。但是,我无法捕获sql异常(ide说它们从未抛出),我只能看到“请求失败,状态代码为500”。我该怎么办?道:

@Override
    public void delete(Integer id) {
        SqlParameterSource parameters = new MapSqlParameterSource().addValue("ID_SETTINGS", id);
            namedParameterJdbcTemplate.update(DELETE_SQL, parameters);
    }

控制器:

@DeleteMapping("/{id}")
    public ResponseEntity<?> delete(@PathVariable("id") Integer id) throws RuntimeException {
        log.info("Request for delete settings {}", id);
        try{
            Settings settings = settingsService.findById(id);
        settingsService.delete(settings.getId());
        log.info("SUCCESS: {} deleted.", settings.getId());
        return new ResponseEntity<>(settings.getId() + " deleted successfully.", HttpStatus.NO_CONTENT);
        } catch (RuntimeException e) {
            System.out.println("CAUSE Controller: "+e.getCause().getMessage());
            throw new RuntimeException("Error during deletion: " + e.getCause().getMessage());
        }
    }

axios公司:

delete(id) {
        return axios.delete(`${BASE_URL}/${id}`, ApiService.getAuthHeader());
    }

我在我的组件中将错误消息设置为state。我已经试着去抓,再抓,什么都没变。有没有在axios中读取任何oracle异常的示例?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题