Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #159 from GSM-MSG/158-api-statuscode-error
Browse files Browse the repository at this point in the history
🔀:: api-error-add
  • Loading branch information
baekteun authored Feb 25, 2023
2 parents 6004a73 + cff382f commit c7ebc54
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 131 deletions.
22 changes: 11 additions & 11 deletions .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git",
"state" : {
"revision" : "583de9bd60f66b40e78d08599cc92036c2e7e4e1",
"version" : "0.20220203.2"
"revision" : "d302de612e3d57c6f4afaf087da18fba8eac72a7",
"version" : "0.20220203.1"
}
},
{
"identity" : "boringssl-swiftpm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/boringssl-SwiftPM.git",
"state" : {
"revision" : "dd3eda2b05a3f459fc3073695ad1b28659066eab",
"version" : "0.9.1"
"revision" : "79db6516894a932d0ddaff3b05b9da1e4f6c4069",
"version" : "0.9.0"
}
},
{
Expand Down Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-ios.git",
"state" : {
"revision" : "8440b914756e0d26d4f4d054a1c1581daedfc5b6",
"version" : "1.44.3-grpc"
"revision" : "2af4f6e9c2b18beae228f50b1198c641be859d2b",
"version" : "1.44.2-grpc"
}
},
{
Expand Down Expand Up @@ -104,14 +104,14 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "3e4e743631e86c8c70dbc6efdc7beaa6e90fd3bb",
"version" : "2.1.1"
"revision" : "46c1e6b5ac09d8f82c991061c659f67e573d425d",
"version" : "2.1.0"
}
},
{
"identity" : "realm-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-core.git",
"location" : "https://github.com/realm/realm-core",
"state" : {
"revision" : "b77443ca7fa25407869ca537bf3ae912b1427bff",
"version" : "12.13.0"
Expand All @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "ab3a58b7209a17d781c0d1dbb3e1ff3da306bae8",
"version" : "1.20.3"
"revision" : "e1499bc69b9040b29184f7f2996f7bab467c1639",
"version" : "1.19.0"
}
}
],
Expand Down
26 changes: 23 additions & 3 deletions Service/Sources/Data/DataSource/Remote/API/AuthAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ enum AuthAPI {
}

extension AuthAPI: GCMSAPI {
typealias ErrorType = GCMSError

var domain: GCMSDomain {
return .auth
}
Expand All @@ -30,6 +32,7 @@ extension AuthAPI: GCMSAPI {
return .delete
}
}

var task: Task {
switch self {
case let .login(req):
Expand All @@ -41,6 +44,7 @@ extension AuthAPI: GCMSAPI {
return .requestPlain
}
}

var jwtTokenType: JWTTokenType? {
switch self {
case .refresh:
Expand All @@ -53,10 +57,26 @@ extension AuthAPI: GCMSAPI {
return JWTTokenType.none
}
}
var errorMapper: [Int: Error]? {

var errorMapper: [Int: GCMSError]? {
switch self {
case .login, .refresh, .logout:
return [:]
case .login:
return [
500: .serverError
]

case .refresh:
return [
404: .notFoundUser,
500: .serverError
]

case .logout:
return [
401: .unauthorized,
404: .notFoundUser,
500: .serverError
]
}
}

Expand Down
65 changes: 33 additions & 32 deletions Service/Sources/Data/DataSource/Remote/API/ClubAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,69 +76,70 @@ extension ClubAPI: GCMSAPI {
}
}

var errorMapper: [Int: Error]? {
typealias ErrorType = GCMSError
var errorMapper: [Int: GCMSError]? {
switch self {
case .clubList:
return [
400: GCMSError.invalidInput,
401: GCMSError.unauthorized,
500: GCMSError.serverError
400: .invalidInput,
401: .unauthorized,
500: .serverError
]

case .clubDetail:
return [
401: GCMSError.unauthorized,
404: GCMSError.notFoundUserOrNotFoundClub,
500: GCMSError.serverError
401: .unauthorized,
404: .notFoundUserOrNotFoundClub,
500: .serverError
]

case .createNewClub:
return [
400: GCMSError.invalidInput,
401: GCMSError.unauthorized,
409: GCMSError.alreadyExistClub,
500: GCMSError.serverError
400: .invalidInput,
401: .unauthorized,
409: .alreadyExistClub,
500: .serverError
]

case .updateClub:
return [
400: GCMSError.invalidInput,
401: GCMSError.unauthorized,
403: GCMSError.notClubHead,
404: GCMSError.notFoundClub,
500: GCMSError.serverError
400: .invalidInput,
401: .unauthorized,
403: .notClubHead,
404: .notFoundClub,
500: .serverError
]

case .deleteClub:
return [
401: GCMSError.unauthorized,
403: GCMSError.notClubHead,
404: GCMSError.notFoundClub,
500: GCMSError.serverError
401: .unauthorized,
403: .notClubHead,
404: .notFoundClub,
500: .serverError
]

case .clubOpen:
return [
401: GCMSError.unauthorized,
403: GCMSError.notClubHead,
404: GCMSError.notFoundClub,
500: GCMSError.serverError
401: .unauthorized,
403: .notClubHead,
404: .notFoundClub,
500: .serverError
]

case .clubClose:
return [
401: GCMSError.unauthorized,
403: GCMSError.notClubHead,
404: GCMSError.notFoundClub,
500: GCMSError.serverError
401: .unauthorized,
403: .notClubHead,
404: .notFoundClub,
500: .serverError
]

case .exitClub:
return [
400: GCMSError.noMebmerClub,
401: GCMSError.unauthorized,
404: GCMSError.notFoundClub,
500: GCMSError.serverError
400: .noMebmerClub,
401: .unauthorized,
404: .notFoundClub,
500: .serverError
]
}
}
Expand Down
53 changes: 30 additions & 23 deletions Service/Sources/Data/DataSource/Remote/API/ClubApplicantAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ extension ClubApplicantAPI: GCMSAPI {

var urlPath: String {
switch self {
case let .applicantList(clubID), let .userAccept(clubID, _), let .userReject(clubID, _), let .apply(clubID), let .cancel(clubID):
case let .applicantList(clubID), let .apply(clubID), let .cancel(clubID):
return "/\(clubID)"

case let .userAccept(clubID, _):
return "/\(clubID)/accept"

case let .userReject(clubID, _):
return "/\(clubID)/reject"
}
}

Expand Down Expand Up @@ -59,47 +65,48 @@ extension ClubApplicantAPI: GCMSAPI {
}
}

var errorMapper: [Int: Error]? {
typealias ErrorType = ClubApplicantError
var errorMapper: [Int: ClubApplicantError]? {
switch self {
case .applicantList:
return[
400: ClubApplicantError.notClubMember,
401: ClubApplicantError.unauthorized,
404: ClubApplicantError.notFoundClub,
500: ClubApplicantError.serverError
400: .notClubMember,
401: .unauthorized,
404: .notFoundClub,
500: .serverError
]

case .apply:
return[
401: ClubApplicantError.unauthorized,
403: ClubApplicantError.alreadyClubMember,
404: ClubApplicantError.notFoundClub,
500: ClubApplicantError.serverError
401: .unauthorized,
403: .alreadyClubMemberOrSameTypeClub,
404: .notFoundClub,
500: .serverError
]

case .cancel:
return[
401: ClubApplicantError.unauthorized,
404: ClubApplicantError.notFoundClub,
500: ClubApplicantError.serverError
401: .unauthorized,
404: .notFoundClub,
500: .serverError
]

case .userAccept:
return[
400: ClubApplicantError.bodyIsNull,
401: ClubApplicantError.unauthorized,
403: ClubApplicantError.notClubHead,
404: ClubApplicantError.notFoundAcceptUser,
500: ClubApplicantError.serverError
400: .bodyIsNull,
401: .unauthorized,
403: .notClubHead,
404: .notFoundAcceptUserOrClub,
500: .serverError
]

case .userReject:
return[
400: ClubApplicantError.bodyIsNull,
401: ClubApplicantError.unauthorized,
403: ClubApplicantError.notClubHead,
404: ClubApplicantError.notFoundRejectUser,
500: ClubApplicantError.serverError
400: .bodyIsNull,
401: .unauthorized,
403: .notClubHead,
404: .notFoundRejectUserOrClub,
500: .serverError
]
}
}
Expand Down
31 changes: 16 additions & 15 deletions Service/Sources/Data/DataSource/Remote/API/ClubMemberAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,33 @@ extension ClubMemberAPI: GCMSAPI {
}
}

var errorMapper: [Int: Error]? {
typealias ErrorType = ClubMemberError
var errorMapper: [Int: ClubMemberError]? {
switch self {
case .clubMember:
return [
401: ClubMemberError.unauthorized,
403: ClubMemberError.notClubMember,
404: ClubMemberError.notFoundClub,
500: ClubMemberError.serverError
401: .unauthorized,
403: .notClubMember,
404: .notFoundClub,
500: .serverError
]

case .userKick:
return [
400: ClubMemberError.kickMyself,
401: ClubMemberError.unauthorized,
403: ClubMemberError.notClubHead,
404: ClubMemberError.notFoundClub,
500: ClubMemberError.serverError
400: .kickMyself,
401: .unauthorized,
403: .notClubHead,
404: .notFoundClubOrKickUser,
500: .serverError
]

case .delegation:
return [
400: ClubMemberError.delegationMyself,
401: ClubMemberError.unauthorized,
403: ClubMemberError.notClubHead,
404: ClubMemberError.notFoundClub,
500: ClubMemberError.serverError
400: .delegationMyself,
401: .unauthorized,
403: .notClubHead,
404: .notFoundClub,
500: .serverError
]
}
}
Expand Down
3 changes: 2 additions & 1 deletion Service/Sources/Data/DataSource/Remote/API/GCMSAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import Moya
import Foundation

protocol GCMSAPI: TargetType, JWTTokenAuthorizable {
associatedtype ErrorType: Error
var domain: GCMSDomain { get }
var urlPath: String { get }
var errorMapper: [Int: Error]? { get }
var errorMapper: [Int: ErrorType]? { get }
}

extension GCMSAPI {
Expand Down
11 changes: 9 additions & 2 deletions Service/Sources/Data/DataSource/Remote/API/ImageAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ extension ImageAPI: GCMSAPI {
return ["Content-type": "multipart/form-data"]
}

var errorMapper: [Int: Error]? {
return .none
typealias ErrorType = GCMSError
var errorMapper: [Int: GCMSError]? {
switch self {
case .uploadImages:
return[
400: .overFourPhoto,
500: .photoUploadFailed
]
}
}
}
Loading

0 comments on commit c7ebc54

Please sign in to comment.