Fix error handling in middleware
Merge branch 'brandur-example'