[WIP] error handling middleware