Added post function, handling errors and before middleware.