Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HashLoad/handle-exception
Middleware for handle exception in HORSE
https://github.com/HashLoad/handle-exception
exceptions handler horse middleware
Last synced: 3 months ago
JSON representation
Middleware for handle exception in HORSE
- Host: GitHub
- URL: https://github.com/HashLoad/handle-exception
- Owner: HashLoad
- License: mit
- Created: 2019-09-03T17:09:07.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-28T13:51:21.000Z (11 months ago)
- Last Synced: 2024-04-14T00:32:21.910Z (7 months ago)
- Topics: exceptions, handler, horse, middleware
- Language: Pascal
- Homepage:
- Size: 90.8 KB
- Stars: 36
- Watchers: 10
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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**](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
```delphi
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) // It has to be before the exceptions middleware
.Use(HandleException);THorse.Post('/ping',
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
begin
// Manage your exceptions:
raise EHorseException.New.Error('My Error!');
end);THorse.Listen(9000);
end;
```## ⚡️ Quickstart Lazarus
```delphi
{$MODE DELPHI}{$H+}uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Horse,
Horse.Jhonson, // It's necessary to use the unit
Horse.HandleException, // It's necessary to use the unit
SysUtils;procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
begin
// Manage your exceptions:
raise EHorseException.New.Error('My Error!');
end;begin
// It's necessary to add the middlewares in the Horse:
THorse
.Use(Jhonson) // It has to be before the exceptions middleware
.Use(HandleException);THorse.Get('/ping', GetPing);
THorse.Listen(9000);
end.
```## ⚠️ License
`handle-exception` is free and open-source middleware licensed under the [MIT License](https://github.com/HashLoad/handle-exception/blob/master/LICENSE).