Skip to content

Latest commit

 

History

History
74 lines (58 loc) · 1.89 KB

error.md

File metadata and controls

74 lines (58 loc) · 1.89 KB

Error

back

Table of Contents

Introduction

When exception raised, Basolato will catch excepton and return Exception status response.

raise newException(Error403, "session timeout")

It return 403 response and 'session timeout' will be in response body.

Basolato have all response status exception type from 300 to 505
List of HTTP Status

ErrorAuthRedirect

If session id is invalid then you want to redirect and delete cookie, raise ErrorAuthRedirect exception.

if not newAuth(request).isLogin():
  raise newException(ErrorAuthRedirect, "/login")

Raise Error and Redirect

If you want to redirect when error raised, you can use errorRedirect proc.
This proc is able to used only in controller or middleware.

errorRedirect("/login")

How to display custom error page

These raised exception is caught in framework routing

main.nim

routes:
  # Framework
  error Http404: http404Route
  error Exception: exceptionRoute

Basolate have it's own error page. If you set arg which is path to HTML file in http404Route and exceptionRoute, you can display custom error page.

main.nim

routes:
  # Framework
  error Http404:
    http404Route("errors/original404.html")
  error Exception:
    exceptionRoute("errors/originalError.html")

This path should be related path from resources dir.

└── resources
    └── errors
        ├── original404.html # user custom error
        └── originalError.html # user custom error