Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

handle-exception

Middleware for handle exception in HORSE

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

handle-exception

Handle-exception is an 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 an 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:

bash
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

pascal
../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.