Error handling and added valid and message to security handler