Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RomeroYang committed Jul 30, 2024
1 parent 34b9c16 commit f967a9a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions RPC/Sources/RPC/RPCController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ final class RPCController: RouteCollection {
} catch {
let rpcError = RPCError(code: -32600, message: "Invalid Request")
let rpcResponse = RPCResponse<RPCError>(jsonrpc: "2.0", result: nil, error: rpcError, id: nil)
return req.eventLoop.makeSucceededFuture(Response(status: .badRequest, body: .init(data: try! JSONEncoder().encode(rpcResponse))))

do {
let responseData = try JSONEncoder().encode(rpcResponse)
return req.eventLoop.makeSucceededFuture(Response(status: .badRequest, body: .init(data: responseData)))
} catch {
// Handle the error appropriately, e.g., log it
print("Failed to send WebSocket error response: \(error)")
}
}
}

Expand All @@ -38,14 +45,14 @@ final class RPCController: RouteCollection {
let result = try handleMethod(rpcRequest.method, params: rpcRequest.params?.value)
let rpcResponse = RPCResponse(jsonrpc: "2.0", result: AnyContent(result ?? ""), error: nil, id: rpcRequest.id)
let responseData = try JSONEncoder().encode(rpcResponse)
try await ws.send(String(data: responseData, encoding: .utf8)!)
try await ws.send(String(decoding: responseData, as: UTF8.self))
} catch {
let rpcError = RPCError(code: -32600, message: "Invalid Request")
let rpcResponse = RPCResponse<RPCError>(jsonrpc: "2.0", result: nil, error: rpcError, id: nil)

do {
let responseData = try JSONEncoder().encode(rpcResponse)
try await ws.send(String(data: responseData, encoding: .utf8)!)
try await ws.send(String(decoding: responseData, as: UTF8.self))
} catch {
// Handle the error appropriately, e.g., log it
print("Failed to send WebSocket error response: \(error)")
Expand Down

0 comments on commit f967a9a

Please sign in to comment.