Improved handling of errors

This improves the error handling a bit, so errors can easier be introspected when they happen. This is to have better error handling for know cases, f.ex. expired tokens.