Changed errors to throw exceptions instead of triggering errors and exiting
Added check in api request to check for authentication errors