+ actix_web::HttpResponse::build(self.status_code()).json(&self.error_type)
+ }
+}
+
+#[derive(Display, Debug, Serialize, Deserialize, Clone, PartialEq, EnumIter)]
+#[cfg_attr(feature = "full", derive(TS))]
+#[cfg_attr(feature = "full", ts(export))]
+#[serde(tag = "error", content = "message", rename_all = "snake_case")]
+// TODO: order these based on the crate they belong to (utils, federation, db, api)
+pub enum LemmyErrorType {
+ ReportReasonRequired,
+ ReportTooLong,
+ NotAModerator,
+ NotAnAdmin,
+ CantBlockYourself,
+ CantBlockAdmin,
+ CouldntUpdateUser,
+ PasswordsDoNotMatch,
+ EmailNotVerified,
+ EmailRequired,
+ CouldntUpdateComment,
+ CouldntUpdatePrivateMessage,
+ CannotLeaveAdmin,
+ NoLinesInHtml,
+ SiteMetadataPageIsNotDoctypeHtml,
+ PictrsResponseError(String),
+ PictrsPurgeResponseError(String),
+ ImageUrlMissingPathSegments,
+ ImageUrlMissingLastPathSegment,
+ PictrsApiKeyNotProvided,
+ NoContentTypeHeader,
+ NotAnImageType,
+ NotAModOrAdmin,
+ NoAdmins,
+ NotTopAdmin,
+ NotTopMod,
+ NotLoggedIn,
+ SiteBan,
+ Deleted,
+ BannedFromCommunity,
+ CouldntFindCommunity,
+ CouldntFindPerson,
+ PersonIsBlocked,
+ DownvotesAreDisabled,
+ InstanceIsPrivate,
+ InvalidPassword,
+ SiteDescriptionLengthOverflow,
+ HoneypotFailed,
+ RegistrationApplicationIsPending,
+ CantEnablePrivateInstanceAndFederationTogether,
+ Locked,
+ CouldntCreateComment,
+ MaxCommentDepthReached,
+ NoCommentEditAllowed,
+ OnlyAdminsCanCreateCommunities,
+ CommunityAlreadyExists,
+ LanguageNotAllowed,
+ OnlyModsCanPostInCommunity,
+ CouldntUpdatePost,
+ NoPostEditAllowed,
+ CouldntFindPost,
+ EditPrivateMessageNotAllowed,
+ SiteAlreadyExists,
+ ApplicationQuestionRequired,
+ InvalidDefaultPostListingType,
+ RegistrationClosed,
+ RegistrationApplicationAnswerRequired,
+ EmailAlreadyExists,
+ FederationForbiddenByStrictAllowList,
+ PersonIsBannedFromCommunity,
+ ObjectIsNotPublic,
+ InvalidCommunity,
+ CannotCreatePostOrCommentInDeletedOrRemovedCommunity,
+ CannotReceivePage,
+ NewPostCannotBeLocked,
+ OnlyLocalAdminCanRemoveCommunity,
+ OnlyLocalAdminCanRestoreCommunity,
+ NoIdGiven,
+ IncorrectLogin,
+ InvalidQuery,
+ ObjectNotLocal,
+ PostIsLocked,
+ PersonIsBannedFromSite,
+ InvalidVoteValue,
+ PageDoesNotSpecifyCreator,
+ PageDoesNotSpecifyGroup,
+ NoCommunityFoundInCc,
+ NoEmailSetup,
+ EmailSmtpServerNeedsAPort,
+ MissingAnEmail,
+ RateLimitError,
+ InvalidName,
+ InvalidDisplayName,
+ InvalidMatrixId,
+ InvalidPostTitle,
+ InvalidBodyField,
+ BioLengthOverflow,
+ MissingTotpToken,
+ IncorrectTotpToken,
+ CouldntParseTotpSecret,
+ CouldntLikeComment,
+ CouldntSaveComment,
+ CouldntCreateReport,
+ CouldntResolveReport,
+ CommunityModeratorAlreadyExists,
+ CommunityUserAlreadyBanned,
+ CommunityBlockAlreadyExists,
+ CommunityFollowerAlreadyExists,
+ CouldntUpdateCommunityHiddenStatus,
+ PersonBlockAlreadyExists,
+ UserAlreadyExists,
+ TokenNotFound,
+ CouldntLikePost,
+ CouldntSavePost,
+ CouldntMarkPostAsRead,
+ CouldntUpdateCommunity,
+ CouldntUpdateReplies,
+ CouldntUpdatePersonMentions,
+ PostTitleTooLong,
+ CouldntCreatePost,
+ CouldntCreatePrivateMessage,
+ CouldntUpdatePrivate,
+ SystemErrLogin,
+ CouldntSetAllRegistrationsAccepted,
+ CouldntSetAllEmailVerified,
+ Banned,
+ CouldntGetComments,
+ CouldntGetPosts,
+ InvalidUrl,
+ EmailSendFailed,
+ Slurs,
+ CouldntGenerateTotp,
+ CouldntFindObject,
+ RegistrationDenied(String),
+ FederationDisabled,
+ DomainBlocked,
+ DomainNotInAllowList,
+ FederationDisabledByStrictAllowList,
+ SiteNameRequired,
+ SiteNameLengthOverflow,
+ PermissiveRegex,
+ InvalidRegex,
+ CaptchaIncorrect,
+ PasswordResetLimitReached,
+ CouldntCreateAudioCaptcha,
+ InvalidUrlScheme,
+ CouldntSendWebmention,
+ Unknown(String),
+}
+
+impl From<LemmyErrorType> for LemmyError {
+ fn from(error_type: LemmyErrorType) -> Self {
+ let inner = anyhow::anyhow!("{}", error_type);
+ LemmyError {
+ error_type,
+ inner,
+ context: SpanTrace::capture(),