Add proper error handling for when the post exceeds character limits
This commit is contained in:
parent
dce27de733
commit
c4e4f7d0e4
2 changed files with 16 additions and 1 deletions
|
|
@ -504,4 +504,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||
"inReplyTo" => object.data["id"]
|
||||
}
|
||||
end
|
||||
|
||||
def validate_character_limit(full_payload, attachments, limit) do
|
||||
length = String.length(full_payload)
|
||||
|
||||
if length < limit do
|
||||
if length > 0 or Enum.count(attachments) > 0 do
|
||||
:ok
|
||||
else
|
||||
{:error, "Cannot post an empty status without attachments"}
|
||||
end
|
||||
else
|
||||
{:error, "The status is over the character limit"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue