Not sure it's the best error handling method but it works