dromara/Sa-Token · error · SaSsoException

CODE_30022

CODE_30022

Error message

消息类型不可为空

What it means

Thrown by SaSsoMessage.checkType() when the message's type field (MSG_TYPE) is empty or null. In sa-token SSO, every SaSsoMessage exchanged between client and server must declare a type so that SaSsoMessageHolder can route it to a registered handler; an empty type makes the message unroutable.

Source

Thrown at sa-token-plugin/sa-token-sso/src/main/java/cn/dev33/satoken/sso/message/SaSsoMessage.java:88

    public String getType() {
        return getString(MSG_TYPE);
    }

    /**
     * 设置消息类型
     * @param type /
     * @return /
     */
    public SaSsoMessage setType(String type) {
        return set(MSG_TYPE, type);
    }

    /**
     * 校验消息类型
     */
    public void checkType() {
        if(SaFoxUtil.isEmpty(getString(MSG_TYPE))) {
            throw new SaSsoException("消息类型不可为空").setCode(SaSsoErrorCode.CODE_30022);
        }
    }

    // -----------

    @Override
    public Object get(String key) {
        return super.get(key);
    }

    @Override
    public SaSsoMessage set(String key, Object value) {
        super.put(key, value);
        return this;
    }

    @Override
    public SaSsoMessage delete(String key) {

View on GitHub (pinned to ac2c7f6e94)

Solutions

  1. Call setType("your-message-type") on the message before checkType() or before sending it
  2. When parsing inbound messages, validate and set the type from the request parameter before invoking handleMessage
  3. Register the type string in SaSsoMessageHolder so routing also succeeds after the check passes

Example fix

// before
SaSsoMessage msg = new SaSsoMessage();
msg.set("key", "value");
msg.checkType(); // throws CODE_30022

// after
SaSsoMessage msg = new SaSsoMessage();
msg.setType("sso-signout");
msg.set("key", "value");
msg.checkType();
Defensive patterns

Strategy: validation

Validate before calling

if(SaFoxUtil.isEmpty(message.getString(SaSsoMessage.MSG_TYPE))) {
    // reject / set default type before dispatch
    message.setType("default-type");
}

Try / catch

try { message.checkType(); } catch (SaSsoException e) { /* code 30022: log and reject inbound message */ }

Prevention

When it happens

Trigger: Calling message.checkType() on a SaSsoMessage that was built without setType(...), e.g. a custom message created via new SaSsoMessage() or parsed from a request body that lacks the type key.

Common situations: Writing a custom SSO message handler; deserializing an incoming SSO HTTP request payload where the client omitted the type field; upgrading to a sa-token version that made checkType() mandatory before dispatch.

Related errors


AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14). Data as JSON: /api/errors/49214fe346763b2f. Report an issue: GitHub.