Skip to content

Commit

Permalink
Add last database error to exception message.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Sep 21, 2022
1 parent e42344b commit 3a7917e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Payments/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public function save() {
* @throws \Exception Throws exception when adding note fails.
*/
public function add_note( $note ) {
global $wpdb;

if ( null === $this->id ) {
throw new \Exception(
\sprintf(
Expand All @@ -183,11 +185,18 @@ public function add_note( $note ) {
$result = \wp_insert_comment( $commentdata );

if ( false === $result ) {
/**
* Should we throw an exception or handle this in some other way?
*
* @link https://github.com/pronamic/wp-pronamic-pay/issues/337
* @todo
*/
throw new \Exception(
\sprintf(
'Could not add note "%s" to payment with ID "%d".',
'Could not add note "%s" to payment with ID "%d", last database error: "%s".',
$note,
$this->id
$this->id,
$wpdb->last_error
)
);
}
Expand Down

0 comments on commit 3a7917e

Please sign in to comment.