mike/errors

Source   Edit  

Extra errors that can be used. These errors contain pre set status codes so you don't need to handle them

You should use the constructors so that the status codes match up to the name

Example:

import mike/errors
try:
  raise newNotFoundError("Could not find something")
except HttpError as e:
  assert e.status == Http404

Types

BadRequestError = object of HttpError
Source   Edit  
ForbiddenError = object of HttpError
Source   Edit  
HttpError = object of CatchableError
  status*: HttpCode
Like normal error except it has a status assoicated with it which is used instead of normal 400 status when thrown Source   Edit  
NotFoundError = object of HttpError
Source   Edit  
ProblemResponse = object
  kind*, detail*: string
  status*: HttpCode
Based losely on RFC7807. Kind (same as type) refers to the name of the exception and is not a dereferenable URI. Source   Edit  
UnAuthorisedError = object of HttpError
Source   Edit  

Procs

proc newBadRequestError(msg`gensym5: string): ref BadRequestError {.inline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newForbiddenError(msg`gensym7: string): ref ForbiddenError {.inline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newInternalServerError(msg`gensym10: string): ref InternalServerError {.
    inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newNotFoundError(msg`gensym8: string): ref NotFoundError {.inline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newRangeNotSatisfiableError(msg`gensym9: string): ref RangeNotSatisfiableError {.
    inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc newUnAuthorisedError(msg`gensym6: string): ref UnAuthorisedError {.inline,
    ...raises: [], tags: [], forbids: [].}
Source   Edit  

Macros

macro makeErrorConstructor(name: untyped; code: HttpCode): untyped
Use this to make your own constructor for a status code. Also makes a new type which inherits HttpError

Example:

makeErrorConstructor(Teapot, Http418)
try:
  raise newTeapotError("I'm a teapot")
except HttpError as e:
  assert e.status == Http418
  assert e.msg == "I'm a teapot"
Source   Edit