-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa6c992
commit 706ae9a
Showing
1 changed file
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,54 @@ | ||
# handle-exception | ||
Middleware for handle exception in HORSE | ||
<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. | ||
<br>We created a channel on Telegram for questions and support:<br><br> | ||
<a href="https://t.me/hashload"> | ||
<img src="https://img.shields.io/badge/telegram-join%20channel-7289DA?style=flat-square"> | ||
</a> | ||
|
||
Sample Horse Server | ||
## ⭕ Prerequisites | ||
[**jhonson**](https://github.com/HashLoad/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`](https://github.com/HashLoad/boss) command: | ||
``` sh | ||
$ 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* | ||
``` | ||
../handle-exception/src | ||
``` | ||
|
||
## ✔️ Compatibility | ||
This middleware is compatible with projects developed in: | ||
- [X] Delphi | ||
- [X] Lazarus | ||
|
||
## ⚡️ Quickstart | ||
```delphi | ||
uses Horse, Horse.Jhonson, Horse.HandleException, System.SysUtils; | ||
uses | ||
Horse, | ||
Horse.Jhonson, // It's necessary to use the unit | ||
Horse.HandleException, // It's necessary to use the unit | ||
System.JSON; | ||
begin | ||
// It's necessary to add the middlewares in the Horse: | ||
THorse | ||
.Use(Jhonson()) | ||
.Use(Jhonson) // It has to be before the exceptions middleware | ||
.Use(HandleException); | ||
THorse.Get('/ping', | ||
THorse.Post('/ping', | ||
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) | ||
begin | ||
// Manage your exceptions: | ||
raise EHorseException.Create('My Error!'); | ||
end); | ||
THorse.Listen(9000); | ||
end. | ||
end; | ||
``` | ||
|
||
## ⚠️ License | ||
`handle-exception` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/handle-exception/blob/master/LICENSE). |