|
1 | 1 | # handle-exception |
2 | | -Middleware for handle exception in HORSE |
| 2 | +<b>Handle-exception</b> is a official middleware for handling exceptions in APIs developed with the <a href="https://github.com/HashLoad/horse">Horse</a> framework. |
| 3 | +<br>We created a channel on Telegram for questions and support:<br><br> |
| 4 | +<a href="https://t.me/hashload"> |
| 5 | + <img src="https://img.shields.io/badge/telegram-join%20channel-7289DA?style=flat-square"> |
| 6 | +</a> |
3 | 7 |
|
4 | | -Sample Horse Server |
| 8 | +## ⭕ Prerequisites |
| 9 | +[**jhonson**](https://github.com/HashLoad/jhonson) - Jhonson is a official middleware for working with JSON in APIs developed with the Horse framework. |
| 10 | + |
| 11 | +*Obs: If you use Boss (dependency manager for Delphi), the jhonson will be installed automatically when installing handle-exception.* |
| 12 | + |
| 13 | +## ⚙️ Installation |
| 14 | +Installation is done using the [`boss install`](https://github.com/HashLoad/boss) command: |
| 15 | +``` sh |
| 16 | +$ boss install handle-exception |
| 17 | +``` |
| 18 | +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* |
| 19 | +``` |
| 20 | +../handle-exception/src |
| 21 | +``` |
| 22 | + |
| 23 | +## ✔️ Compatibility |
| 24 | +This middleware is compatible with projects developed in: |
| 25 | +- [X] Delphi |
| 26 | +- [X] Lazarus |
| 27 | + |
| 28 | +## ⚡️ Quickstart |
5 | 29 | ```delphi |
6 | | -uses Horse, Horse.Jhonson, Horse.HandleException, System.SysUtils; |
| 30 | +uses |
| 31 | + Horse, |
| 32 | + Horse.Jhonson, // It's necessary to use the unit |
| 33 | + Horse.HandleException, // It's necessary to use the unit |
| 34 | + System.JSON; |
7 | 35 |
|
8 | 36 | begin |
| 37 | + // It's necessary to add the middlewares in the Horse: |
9 | 38 | THorse |
10 | | - .Use(Jhonson()) |
| 39 | + .Use(Jhonson) // It has to be before the exceptions middleware |
11 | 40 | .Use(HandleException); |
12 | 41 |
|
13 | | - THorse.Get('/ping', |
| 42 | + THorse.Post('/ping', |
14 | 43 | procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) |
15 | 44 | begin |
| 45 | + // Manage your exceptions: |
16 | 46 | raise EHorseException.Create('My Error!'); |
17 | 47 | end); |
18 | 48 |
|
19 | 49 | THorse.Listen(9000); |
20 | | -end. |
| 50 | +end; |
21 | 51 | ``` |
| 52 | + |
| 53 | +## ⚠️ License |
| 54 | +`handle-exception` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/handle-exception/blob/master/LICENSE). |
0 commit comments