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

Commit

Permalink
🥅 :: 에러 메시지 표기
Browse files Browse the repository at this point in the history
  • Loading branch information
baekteun committed Feb 25, 2023
1 parent b2d6d17 commit cff382f
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 125 deletions.
19 changes: 12 additions & 7 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,24 +57,25 @@ extension AuthAPI: GCMSAPI {
return JWTTokenType.none
}
}
var errorMapper: [Int: Error]? {

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

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

case .logout:
return [
401: GCMSError.unauthorized,
404: GCMSError.notFoundUser,
500: GCMSError.serverError
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.alreadyClubMemberOrSameTypeClub,
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.notFoundAcceptUserOrClub,
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.notFoundRejectUserOrClub,
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.notFoundClubOrKickUser,
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
7 changes: 4 additions & 3 deletions Service/Sources/Data/DataSource/Remote/API/ImageAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ extension ImageAPI: GCMSAPI {
return ["Content-type": "multipart/form-data"]
}

var errorMapper: [Int: Error]? {
typealias ErrorType = GCMSError
var errorMapper: [Int: GCMSError]? {
switch self {
case .uploadImages:
return[
400: GCMSError.overFourPhoto,
500: GCMSError.photoUploadFailed
400: .overFourPhoto,
500: .photoUploadFailed
]
}
}
Expand Down
25 changes: 13 additions & 12 deletions Service/Sources/Data/DataSource/Remote/API/UserAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,34 @@ extension UserAPI: GCMSAPI {
}
}

var errorMapper: [Int: Error]? {
typealias ErrorType = GCMSError
var errorMapper: [Int: GCMSError]? {
switch self {
case .myProfile, .miniProfile:
return [
401: GCMSError.unauthorized,
404: GCMSError.notFoundUser,
500: GCMSError.serverError
401: .unauthorized,
404: .notFoundUser,
500: .serverError
]

case .editProfile:
return [
400: GCMSError.invalidInput,
401: GCMSError.unauthorized,
404: GCMSError.notFoundUser,
500: GCMSError.serverError
400: .invalidInput,
401: .unauthorized,
404: .notFoundUser,
500: .serverError
]

case .search:
return [
401: GCMSError.unauthorized,
500: GCMSError.serverError
401: .unauthorized,
500: .serverError
]

case .withdrawal:
return [
401: GCMSError.unauthorized,
403: GCMSError.notExistUser
401: .unauthorized,
403: .notExistUser
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ private extension BaseRemote {
return self.reissueToken()
.andThen(.error(TokenError.expired))
}
return .error(api.errorMapper?[code] ?? GCMSError.error(message: (try? (error as? MoyaError)?.response?.mapJSON() as? NSDictionary)?["message"] as? String ?? "", errorBody: [:]))
return .error(
api.errorMapper?[code] ??
GCMSError.error(
message: (try? (error as? MoyaError)?.response?.mapJSON() as? NSDictionary)?["message"] as? String ?? "",
errorBody: [:]
)
)
}
}

Expand Down
Loading

0 comments on commit cff382f

Please sign in to comment.