首页 > 解决方案 > 当客户端发送无效的 uuid 时,服务器应该响应什么错误?

问题描述

我正在使用 Spring Boot 开发微服务。该服务在进入应用程序时生成uuid并发送给客户端,客户端将uuid保存在cookie中。现在,当客户端向资源发出请求时,会有一个过滤器检查 uuid 是否有效。

@Override
    public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain)
            throws IOException, ServletException {
        
        String uuid = req.getParameter("guest_uuid");

        if (isValidUUID(uuid)){
            chain.doFilter(req, res);
        }else {
            // respond with customer error
        }

    }

服务器应该响应什么错误,以便客户端(javascript)可以识别此错误并从 cookie 中删除 uuid?

标签: javascriptspring-boothttpresponse

解决方案


推荐阅读