handle DB connect errors

This commit is contained in:
Christian Grothoff 2015-01-21 14:21:58 +01:00
parent 2ef511eece
commit c9a819a5ef
3 changed files with 34 additions and 15 deletions

View File

@ -25,6 +25,7 @@
* - /deposit: check for leaks * - /deposit: check for leaks
* - ALL: check API: given structs are usually not perfect, as they * - ALL: check API: given structs are usually not perfect, as they
* often contain too many fields for the context * often contain too many fields for the context
* - ALL: check transactional behavior
*/ */
#include "platform.h" #include "platform.h"
#include <pthread.h> #include <pthread.h>
@ -59,8 +60,7 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
GNUNET_break (0); GNUNET_break (0);
return TALER_MINT_reply_internal_error (connection, return TALER_MINT_reply_internal_db_error (connection);
"Failed to connect to database");
} }
res = TALER_MINT_DB_get_deposit (db_conn, res = TALER_MINT_DB_get_deposit (db_conn,
&deposit->coin_pub, &deposit->coin_pub,
@ -176,12 +176,10 @@ TALER_MINT_db_execute_withdraw_status (struct MHD_Connection *connection,
struct MintKeyState *key_state; struct MintKeyState *key_state;
int must_update = GNUNET_NO; int must_update = GNUNET_NO;
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
GNUNET_break (0); GNUNET_break (0);
return TALER_MINT_reply_internal_error (connection, return TALER_MINT_reply_internal_db_error (connection);
"Failed to connect to database");
} }
res = TALER_MINT_DB_get_reserve (db_conn, res = TALER_MINT_DB_get_reserve (db_conn,
reserve_pub, reserve_pub,
@ -245,9 +243,8 @@ TALER_MINT_db_execute_withdraw_sign (struct MHD_Connection *connection,
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
// FIXME: return 'internal error'?
GNUNET_break (0); GNUNET_break (0);
return MHD_NO; return TALER_MINT_reply_internal_db_error (connection);
} }
@ -576,8 +573,8 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection,
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
/* FIXME: return error code to MHD! */ GNUNET_break (0);
return MHD_NO; return TALER_MINT_reply_internal_db_error (connection);
} }
res = TALER_MINT_DB_get_refresh_session (db_conn, res = TALER_MINT_DB_get_refresh_session (db_conn,
refresh_session_pub, refresh_session_pub,
@ -717,9 +714,8 @@ TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection,
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
// FIXME: return 'internal error'?
GNUNET_break (0); GNUNET_break (0);
return MHD_NO; return TALER_MINT_reply_internal_db_error (connection);
} }
/* Send response immediately if we already know the session. /* Send response immediately if we already know the session.
@ -864,8 +860,7 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
{ {
GNUNET_break (0); GNUNET_break (0);
// FIXME: return error code! return TALER_MINT_reply_internal_db_error (connection);
return MHD_NO;
} }
res = TALER_db_get_transfer (db_conn, res = TALER_db_get_transfer (db_conn,
@ -920,6 +915,4 @@ TALER_MINT_db_execute_refresh_link (struct MHD_Connection *connection,
return TALER_MINT_reply_json (connection, return TALER_MINT_reply_json (connection,
root, root,
MHD_HTTP_OK); MHD_HTTP_OK);
} }

View File

@ -171,6 +171,21 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
} }
/**
* Send a response indicating a failure to talk to the Mint's
* database.
*
* @param connection the MHD connection to use
* @return a MHD result code
*/
int
TALER_MINT_reply_internal_db_error (struct MHD_Connection *connection)
{
return TALER_MINT_reply_internal_error (connection,
"Failed to connect to database");
}
/** /**
* Send a response indicating that the request was too big. * Send a response indicating that the request was too big.
* *

View File

@ -103,6 +103,17 @@ TALER_MINT_reply_internal_error (struct MHD_Connection *connection,
const char *hint); const char *hint);
/**
* Send a response indicating a failure to talk to the Mint's
* database.
*
* @param connection the MHD connection to use
* @return a MHD result code
*/
int
TALER_MINT_reply_internal_db_error (struct MHD_Connection *connection);
/** /**
* Send a response indicating that the request was too big. * Send a response indicating that the request was too big.
* *