Service method errors incorrectly reported as -32601 Method not found #1

Closed
opened 2026-03-01 14:09:22 +00:00 by mik-tf · 0 comments
Owner

Problem

When a service method (e.g. authservice.login) returns an application error (wrong password, expired challenge, etc.), the dispatch layer wraps it as JSON-RPC -32601 Method not found instead of a proper application error.

This affects ALL service methods across ALL domains — any handle_service_call error becomes "Method not found".

Root Cause

packages/osis/src/rpc/dispatch.rs line 143-145:

Err(e) => JsonRpcResponse::error(
    req.id.clone(),
    JsonRpcError::method_not_found(&format!("{}: {}", req.method, e)),
),

Service methods go through handle_service_call because their type name (e.g. authservice) is not a CRUD type. When handle_service_call returns Err, the dispatch wraps it with method_not_found instead of a proper error code.

Example

  • Login with wrong password → RPC error [-32601]: Method not found
  • Expected → RPC error [-32000]: Authentication failed

The actual error message ("Authentication failed") is lost because the SDK client reads the message field which is hardcoded to "Method not found".

Fix

  1. Add application_error() constructor to JsonRpcError using code -32000 (JSON-RPC server error range)
  2. Use it in dispatch.rs instead of method_not_found for service call errors
## Problem When a service method (e.g. `authservice.login`) returns an application error (wrong password, expired challenge, etc.), the dispatch layer wraps it as JSON-RPC `-32601 Method not found` instead of a proper application error. This affects ALL service methods across ALL domains — any `handle_service_call` error becomes "Method not found". ## Root Cause `packages/osis/src/rpc/dispatch.rs` line 143-145: ```rust Err(e) => JsonRpcResponse::error( req.id.clone(), JsonRpcError::method_not_found(&format!("{}: {}", req.method, e)), ), ``` Service methods go through `handle_service_call` because their type name (e.g. `authservice`) is not a CRUD type. When `handle_service_call` returns `Err`, the dispatch wraps it with `method_not_found` instead of a proper error code. ## Example - Login with wrong password → `RPC error [-32601]: Method not found` - Expected → `RPC error [-32000]: Authentication failed` The actual error message ("Authentication failed") is lost because the SDK client reads the `message` field which is hardcoded to "Method not found". ## Fix 1. Add `application_error()` constructor to `JsonRpcError` using code `-32000` (JSON-RPC server error range) 2. Use it in `dispatch.rs` instead of `method_not_found` for service call errors
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_rpc#1
No description provided.