项目作者: HashLoad

项目描述 :
Middleware for handle exception in HORSE
高级语言: Pascal
项目地址: git://github.com/HashLoad/handle-exception.git
创建时间: 2019-09-03T17:09:07Z
项目社区:https://github.com/HashLoad/handle-exception

开源协议:MIT License

下载


handle-exception

Handle-exception is a official middleware for handling exceptions in APIs developed with the Horse framework.

We created a channel on Telegram for questions and support:




⭕ Prerequisites

jhonson - Jhonson is a official middleware for working with JSON in APIs developed with the Horse framework.

Obs: If you use Boss (dependency manager for Delphi), the jhonson will be installed automatically when installing handle-exception.

⚙️ Installation

Installation is done using the boss install command:

  1. boss install handle-exception

If you choose to install manually, simply add the following folders to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path

  1. ../handle-exception/src

✔️ Compatibility

This middleware is compatible with projects developed in:

  • [X] Delphi
  • [X] Lazarus

⚡️ Quickstart Delphi

  1. uses
  2. Horse,
  3. Horse.Jhonson, // It's necessary to use the unit
  4. Horse.HandleException, // It's necessary to use the unit
  5. System.JSON;
  6. begin
  7. // It's necessary to add the middlewares in the Horse:
  8. THorse
  9. .Use(Jhonson) // It has to be before the exceptions middleware
  10. .Use(HandleException);
  11. THorse.Post('/ping',
  12. procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
  13. begin
  14. // Manage your exceptions:
  15. raise EHorseException.New.Error('My Error!');
  16. end);
  17. THorse.Listen(9000);
  18. end;

⚡️ Quickstart Lazarus

  1. {$MODE DELPHI}{$H+}
  2. uses
  3. {$IFDEF UNIX}{$IFDEF UseCThreads}
  4. cthreads,
  5. {$ENDIF}{$ENDIF}
  6. Horse,
  7. Horse.Jhonson, // It's necessary to use the unit
  8. Horse.HandleException, // It's necessary to use the unit
  9. SysUtils;
  10. procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
  11. begin
  12. // Manage your exceptions:
  13. raise EHorseException.New.Error('My Error!');
  14. end;
  15. begin
  16. // It's necessary to add the middlewares in the Horse:
  17. THorse
  18. .Use(Jhonson) // It has to be before the exceptions middleware
  19. .Use(HandleException);
  20. THorse.Get('/ping', GetPing);
  21. THorse.Listen(9000);
  22. end.

⚠️ License

handle-exception is free and open-source middleware licensed under the MIT License.