clean up error handling slightly
This commit is contained in:
parent
b22c086e10
commit
3ca4cdb37a
|
@ -13,7 +13,8 @@ extern "C" {
|
||||||
|
|
||||||
using namespace i18n::phonenumbers;
|
using namespace i18n::phonenumbers;
|
||||||
|
|
||||||
static const char* parseErrorMessage(PhoneNumberUtil::ErrorType error) {
|
namespace {
|
||||||
|
const char* getParseErrorMessage(PhoneNumberUtil::ErrorType error) {
|
||||||
using PNU = i18n::phonenumbers::PhoneNumberUtil;
|
using PNU = i18n::phonenumbers::PhoneNumberUtil;
|
||||||
switch(error) {
|
switch(error) {
|
||||||
case PNU::NO_PARSING_ERROR:
|
case PNU::NO_PARSING_ERROR:
|
||||||
|
@ -32,6 +33,7 @@ static const char* parseErrorMessage(PhoneNumberUtil::ErrorType error) {
|
||||||
//We have some generic parsing error.
|
//We have some generic parsing error.
|
||||||
return "Unable to parse number";
|
return "Unable to parse number";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -51,12 +53,12 @@ void reportOutOfMemory() {
|
||||||
* depending on the type of the exception
|
* depending on the type of the exception
|
||||||
*/
|
*/
|
||||||
void reportException(const std::exception& exception) {
|
void reportException(const std::exception& exception) {
|
||||||
{
|
|
||||||
const std::bad_alloc* bad_alloc = dynamic_cast<const std::bad_alloc*>(&exception);
|
const std::bad_alloc* bad_alloc = dynamic_cast<const std::bad_alloc*>(&exception);
|
||||||
if(bad_alloc != nullptr) {
|
if(bad_alloc != nullptr) {
|
||||||
reportOutOfMemory();
|
reportOutOfMemory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PhoneNumberTooLongException* too_long =
|
const PhoneNumberTooLongException* too_long =
|
||||||
dynamic_cast<const PhoneNumberTooLongException*>(&exception);
|
dynamic_cast<const PhoneNumberTooLongException*>(&exception);
|
||||||
if(too_long != nullptr) {
|
if(too_long != nullptr) {
|
||||||
|
@ -68,7 +70,6 @@ void reportException(const std::exception& exception) {
|
||||||
errdetail("%s", exception.what())));
|
errdetail("%s", exception.what())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//If we don't have a special way to handle this exception, report
|
//If we don't have a special way to handle this exception, report
|
||||||
//a generic error.
|
//a generic error.
|
||||||
|
@ -82,7 +83,7 @@ void reportParseError(const char* phone_number, PhoneNumberUtil::ErrorType err)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
errmsg("unable to parse '%s' as a phone number", phone_number),
|
errmsg("unable to parse '%s' as a phone number", phone_number),
|
||||||
errdetail("%s", parseErrorMessage(err))));
|
errdetail("%s", getParseErrorMessage(err))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void logInfo(const char* msg) {
|
void logInfo(const char* msg) {
|
||||||
|
|
Loading…
Reference in New Issue