Opened 9 years ago
Closed 9 years ago
#6535 closed enhancement (fixed)
Entering an invalid username when composing a message shows generic error
Reported by: | r-a-y | Owned by: | r-a-y |
---|---|---|---|
Milestone: | 2.4 | Priority: | normal |
Severity: | normal | Version: | 1.0 |
Component: | Messages | Keywords: | has-patch commit |
Cc: |
Description
When an invalid username is entered when composing a message, a generic error message is shown:
Message was not sent. Please try again.
We should output a better error message for users.
I've attached a patch that changes messages_new_message()
to add an $error_type
parameter. When $error_type
is 'wp_error', this uses the WP_Error
API to return error messages.
This will allow us to grab error messages without having to parse out all invalid recipients again in bp_messages_action_create_message()
.
Attachments (2)
Change History (9)
This ticket was mentioned in Slack in #buddypress by boone. View the logs.
9 years ago
This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.
9 years ago
#5
@
9 years ago
Thanks for the feedback, boonebgorges.
I think returning WP_Error messages for this kind of thing is generally a good thing. It stinks that we have to introduce this lame $error_type parameter :(
Yeah, it does. I was thinking that this technique is something we could adopt in some of our older functions that need this type of error message feedback.
So okay to commit?
Good points regarding the following:
For example, is there a reason why an if ( empty( $this->recipients ) ) clause belongs in the database access method?
.
And when something goes wrong in one of these methods that is legitimately database-related - like a failed $wpdb->query() - $wpdb doesn't give us enough information to build an error object anyway.
I think returning
WP_Error
messages for this kind of thing is generally a good thing. It stinks that we have to introduce this lame$error_type
parameter :(As for the question of whether
BP_Messages_Message::send()
should returnWP_Error
messages too: If we were building these systems from scratch, I'd probably lean yes. But given that all of our database-access methods tend to returnfalse
on failure, it'd be a large undertaking to fix them. Better, I think, would be to move business logic out of low-level functions likesend()
and into the controllers likemessages_new_message()
. For example, is there a reason why anif ( empty( $this->recipients ) )
clause belongs in the database access method? At a database level, there's nothing wrong with a message without recipients; it's only further up in the application that it's a problem. And when something goes wrong in one of these methods that is legitimately database-related - like a failed$wpdb->query()
-$wpdb
doesn't give us enough information to build an error object anyway.