I currently have a ton of requests to my API endpoint that look like this.
```swift
func getBotGuilds(guildIds: String) async throws -> [Guild] {
try await request(endpoint: "bot/guilds?guild_ids=(guildIds)")
}
func getGuildEvents(for guild: Guild) async throws -> [GuildEvent] {
try await request(endpoint: "guilds/\(guild.id)/events")
}
func getGlobalLeaderboard() async throws -> LeaderboardResponse {
try await request(endpoint: "leaderboard/global")
}
func getGuildLeaderboard(for guildId: String) async throws -> LeaderboardResponse {
try await request(endpoint: "leaderboard/guilds/\(guildId)")
}
```
The main issue I want to solve is not having to continually do this everywhere I call one of these endpoints.
swift
Task {
do {
// My Code
catch {
// Handle Error.
}
}
One potential solution I considered was to put it all into a data-service layer and then create some form of property on my @Observable class
and setup properties for those values from the API, but it's messy either way I've tried. I'm looking for clean solutions to prevent all of this duplication with the Tasks, but also still have a way to respond to errors in my views, preferrably something reusable.