zoukankan      html  css  js  c++  java
  • [转载红鱼儿]kbmmw 开发点滴:Authorization failed.

    开始利用kbmmw实作项目,第一件事就是为的服务端加用户的认证。如果客户端发来的请求无法在服务器端通过认证,即客户端认证失败,会在客户端弹出一个错误提示窗口:Authorization failed.总不能让用户看到这样的提示信息,得想办法,截获这样的错误,并给出自己的提示。没想到,费了一翻周拆,最终发现,kbmMW没有提供机制来处理这样的问题。

    先看看服务器在哪里处理这样的错误:

    单元:kwmMWServer

    方法:procedure TkbmMWServer.InternalServeMessagePart

    'Authorization failed.')

    行号:5118,5182

    服务器端直接把错误写到了返回流中,明显看出,作者没有想到多语言的问题。

    再看客户端:

    单元:kbmMWClient

    方法:function TkbmMWCustomClient.InternalSendRequest

    代码:

                      if tResponseStream.IsError then
                      begin
                           case tResponseStream.StatusCode of
                                -KBMMW_ERR_AUTHFAILED: raise EkbmMWAuthException.Create(KBMMW_ERR_AUTHFAILED,tResponseStream.StatusText);
    行号:864

    客户端直接判断返回的流有错,则raise服务器端返回的错误信息!

    解决方法:

    1.把出错信息改成汉字

    2.在TkbmMWCustomClient修改源码,增加事件,支持用户处理错误

    3.在服务器端kbmMWServer.OnServerResponse事件中定制。

    procedure TForm1.kbmMWServer1ServeResponse(Sender: TObject;
      OutStream: IkbmMWCustomResponseTransportStream; Service: TkbmMWCustomService;
      ClientIdent: TkbmMWClientIdentity; Args: TkbmMWVariantList);
    begin
      with OutStream do begin
            case StatusCode of
                -KBMMW_ERR_AUTHFAILED:StatusText:='服务器无法确认用户身份';
                -KBMMW_ERR_FUNCNOTAVAIL:StatussText:='服务不可用';

                -KBMMW_ERR_ABORT:;

                -KBMMW_ERR_SERVICENOTAVAIL:;

            end;
      end;
    end;

  • 相关阅读:
    使用 Vim 搭建 JavaScript 开发环境
    SpaceVim 语言模块 erlang
    SpaceVim 语言模块 lua
    SpaceVim 语言模块 python
    SpaceVim 语言模块 elixir
    SpaceVim 语言模块 dart
    SpaceVim 语言模块 elm
    如何配置 SpaceVim
    彻底理解浏览器缓存机制
    react-创建react元素
  • 原文地址:https://www.cnblogs.com/xalion/p/2718746.html
Copyright © 2011-2022 走看看