Handle errors with correct pages and codes

Resolves #164