Skip to content

Commit

Permalink
♻️ Replace use of framework exception with more generic exception.
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Aug 31, 2024
1 parent 00e2a05 commit ffaa4e7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
public final class DefaultMastodonLoader implements MastodonLoader {

@Override
@NotNull public List<Status> getStatuses(@NotNull final String instance, @NotNull final String hashtag) throws BigBoneRequestException {
@NotNull public List<Status> getStatuses(@NotNull final String instance, @NotNull final String hashtag) throws MastodonException {
final MastodonClient client = new MastodonClient.Builder(instance).build();
final Range range = new Range(null, null, null, 100);
return client.timelines().getTagTimeline(hashtag, LOCAL_AND_REMOTE, range).execute().getPart();
try {
return client.timelines().getTagTimeline(hashtag, LOCAL_AND_REMOTE, range).execute().getPart();
} catch (final BigBoneRequestException e) {
throw new MastodonException(String.format("Unable to load posts with hashtag '%s' from Mastodon instance '%s'", hashtag, instance), e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Apus - A social wall for conferences with additional features.
* Copyright (C) Marcus Fihlon and the individual contributors to Apus.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package swiss.fihlon.apus.plugin.social.mastodon;

import org.jetbrains.annotations.NotNull;

public class MastodonException extends Exception {

public MastodonException(@NotNull final String message, @NotNull final Exception e) {
super(message, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

import org.jetbrains.annotations.NotNull;
import social.bigbone.api.entity.Status;
import social.bigbone.api.exception.BigBoneRequestException;

import java.util.List;

public interface MastodonLoader {
@NotNull List<Status> getStatuses(@NotNull String instance, @NotNull String hashtag) throws BigBoneRequestException;
@NotNull List<Status> getStatuses(@NotNull String instance, @NotNull String hashtag) throws MastodonException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public Stream<Post> getPosts() {
return statuses.stream()
.map(this::convertToPost)
.sorted();
} catch (final Exception e) {
LOGGER.error("Unable to load posts with hashtag '{}' from Mastodon instance '{}': {}",
hashtag, instance, e.getMessage());
} catch (final MastodonException e) {
LOGGER.error(e.getMessage(), e);
return Stream.of();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

import org.junit.jupiter.api.Test;
import social.bigbone.api.entity.Status;
import social.bigbone.api.exception.BigBoneRequestException;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class DefaultMastodonLoaderTest {

@Test
void getStatuses() throws BigBoneRequestException {
void getStatuses() throws MastodonException {
final List<Status> statuses = new DefaultMastodonLoader().getStatuses("ijug.social", "java");
assertNotNull(statuses);
assertFalse(statuses.isEmpty());
Expand Down

0 comments on commit ffaa4e7

Please sign in to comment.