Skip to content

Commit 70820d6

Browse files
authored
Update ParseError codes (#123)
* Update ParseError codes * Update .codecov.yml
1 parent d666556 commit 70820d6

File tree

5 files changed

+108
-39
lines changed

5 files changed

+108
-39
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ coverage:
55
status:
66
patch:
77
default:
8-
target: auto
8+
target: 49
99
changes: false
1010
project:
1111
default:

Sources/ParseSwift/API/URLSession+extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension URLSession {
2929
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
3030
if let responseError = responseError {
3131
guard let parseError = responseError as? ParseError else {
32-
return .failure(ParseError(code: .invalidServerResponse,
32+
return .failure(ParseError(code: .unknownError,
3333
message: "Unable to sync with parse-server: \(responseError)"))
3434
}
3535
return .failure(parseError)
@@ -69,7 +69,7 @@ extension URLSession {
6969
mapper: @escaping (Data) throws -> U) -> Result<U, ParseError> {
7070
if let responseError = responseError {
7171
guard let parseError = responseError as? ParseError else {
72-
return .failure(ParseError(code: .invalidServerResponse,
72+
return .failure(ParseError(code: .unknownError,
7373
message: "Unable to sync with parse-server: \(responseError)"))
7474
}
7575
return .failure(parseError)

Sources/ParseSwift/Types/ParseError.swift

Lines changed: 100 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public struct ParseError: ParseType, Decodable, Swift.Error {
2626
as `code` for `Error` for callbacks on all classes.
2727
*/
2828
public enum Code: Int, Swift.Error, Codable {
29+
2930
/**
3031
Internal SDK Error. No information available
3132
*/
@@ -35,191 +36,248 @@ public struct ParseError: ParseType, Decodable, Swift.Error {
3536
Internal server error. No information available.
3637
*/
3738
case internalServer = 1
39+
3840
/**
3941
The connection to the Parse servers failed.
4042
*/
4143
case connectionFailed = 100
44+
4245
/**
4346
Object doesn't exist, or has an incorrect password.
4447
*/
4548
case objectNotFound = 101
49+
4650
/**
4751
You tried to find values matching a datatype that doesn't
4852
support exact database matching, like an array or a dictionary.
4953
*/
5054
case invalidQuery = 102
55+
5156
/**
5257
Missing or invalid classname. Classnames are case-sensitive.
5358
They must start with a letter, and `a-zA-Z0-9_` are the only valid characters.
5459
*/
5560
case invalidClassName = 103
61+
5662
/**
5763
Missing object id.
5864
*/
5965
case missingObjectId = 104
66+
6067
/**
6168
Invalid key name. Keys are case-sensitive.
6269
They must start with a letter, and `a-zA-Z0-9_` are the only valid characters.
6370
*/
6471
case invalidKeyName = 105
72+
6573
/**
6674
Malformed pointer. Pointers must be arrays of a classname and an object id.
6775
*/
6876
case invalidPointer = 106
77+
6978
/**
7079
Malformed json object. A json dictionary is expected.
7180
*/
7281
case invalidJSON = 107
82+
7383
/**
7484
Tried to access a feature only available internally.
7585
*/
7686
case commandUnavailable = 108
87+
7788
/**
7889
Field set to incorrect type.
7990
*/
8091
case incorrectType = 111
92+
8193
/**
8294
Invalid channel name. A channel name is either an empty string (the broadcast channel)
8395
or contains only `a-zA-Z0-9_` characters and starts with a letter.
8496
*/
8597
case invalidChannelName = 112
98+
8699
/**
87100
Invalid device token.
88101
*/
89102
case invalidDeviceToken = 114
103+
90104
/**
91105
Push is misconfigured. See details to find out how.
92106
*/
93107
case pushMisconfigured = 115
108+
94109
/**
95110
The object is too large.
96111
*/
97112
case objectTooLarge = 116
113+
98114
/**
99115
That operation isn't allowed for clients.
100116
*/
101117
case operationForbidden = 119
118+
102119
/**
103120
The results were not found in the cache.
104121
*/
105122
case cacheMiss = 120
123+
106124
/**
107125
Keys in `NSDictionary` values may not include `$` or `.`.
108126
*/
109127
case invalidNestedKey = 121
128+
110129
/**
111130
Invalid file name.
112131
A file name can contain only `a-zA-Z0-9_.` characters and should be between 1 and 36 characters.
113132
*/
114133
case invalidFileName = 122
134+
115135
/**
116136
Invalid ACL. An ACL with an invalid format was saved. This should not happen if you use `ACL`.
117137
*/
118138
case invalidACL = 123
139+
119140
/**
120141
The request timed out on the server. Typically this indicates the request is too expensive.
121142
*/
122143
case timeout = 124
144+
123145
/**
124146
The email address was invalid.
125147
*/
126148
case invalidEmailAddress = 125
149+
127150
/**
128-
A unique field was given a value that is already taken.
129-
*/
130-
case duplicateValue = 137
131-
/**
132-
Role's name is invalid.
151+
Missing content type.
133152
*/
134-
case invalidRoleName = 139
153+
case missingContentType = 126
154+
135155
/**
136-
Exceeded an application quota. Upgrade to resolve.
156+
Missing content length.
137157
*/
138-
case exceededQuota = 140
158+
case missingContentLength = 127
159+
139160
/**
140-
Cloud Code script had an error.
161+
Invalid content length.
141162
*/
142-
case scriptError = 141
163+
case invalidContentLength = 128
164+
143165
/**
144-
Cloud Code validation failed.
166+
File was too large.
145167
*/
146-
case validationError = 142
168+
case fileTooLarge = 129
169+
147170
/**
148-
Product purchase receipt is missing.
171+
Failure saving a file.
149172
*/
150-
case receiptMissing = 143
173+
case fileSaveFailure = 130
174+
151175
/**
152-
Product purchase receipt is invalid.
176+
A unique field was given a value that is already taken.
153177
*/
154-
case invalidPurchaseReceipt = 144
178+
case duplicateValue = 137
179+
155180
/**
156-
Payment is disabled on this device.
181+
Role's name is invalid.
157182
*/
158-
case paymentDisabled = 145
183+
case invalidRoleName = 139
184+
159185
/**
160-
The product identifier is invalid.
186+
Exceeded an application quota. Upgrade to resolve.
161187
*/
162-
case invalidProductIdentifier = 146
188+
case exceededQuota = 140
189+
163190
/**
164-
The product is not found in the App Store.
191+
Cloud Code script had an error.
165192
*/
166-
case productNotFoundInAppStore = 147
193+
case scriptFailed = 141
194+
167195
/**
168-
The Apple server response is not valid.
196+
Cloud Code validation failed.
169197
*/
170-
case invalidServerResponse = 148
198+
case validationFailed = 142
199+
171200
/**
172-
Product fails to download due to file system error.
201+
Fail to convert data to image.
173202
*/
174-
case productDownloadFileSystemFailure = 149
203+
case invalidImageData = 143
204+
175205
/**
176-
Fail to convert data to image.
206+
Unsaved file failure.
177207
*/
178-
case invalidImageData = 150
208+
case unsavedFileFailure = 151
209+
179210
/**
180-
Unsaved file.
211+
An invalid push time.
181212
*/
182-
case unsavedFile = 151
213+
case invalidPushTime = 152
214+
183215
/**
184216
Fail to delete file.
185217
*/
186218
case fileDeleteFailure = 153
219+
220+
/**
221+
Fail to delete an unnamed file.
222+
*/
223+
case fileDeleteUnnamedFailure = 161
224+
187225
/**
188226
Application has exceeded its request limit.
189227
*/
190228
case requestLimitExceeded = 155
229+
230+
/**
231+
The request was a duplicate and has been discarded
232+
due to idempotency rules.
233+
*/
234+
case duplicateRequest = 159
235+
191236
/**
192237
Invalid event name.
193238
*/
194239
case invalidEventName = 160
240+
241+
/**
242+
Invalid value.
243+
*/
244+
case invalidValue = 162
245+
195246
/**
196247
Username is missing or empty.
197248
*/
198249
case usernameMissing = 200
250+
199251
/**
200252
Password is missing or empty.
201253
*/
202254
case userPasswordMissing = 201
255+
203256
/**
204257
Username has already been taken.
205258
*/
206259
case usernameTaken = 202
260+
207261
/**
208262
Email has already been taken.
209263
*/
210264
case userEmailTaken = 203
265+
211266
/**
212267
The email is missing, and must be specified.
213268
*/
214269
case userEmailMissing = 204
270+
215271
/**
216272
A user with the specified email was not found.
217273
*/
218274
case userWithEmailNotFound = 205
275+
219276
/**
220277
The user cannot be altered by a client without the session.
221278
*/
222279
case userCannotBeAlteredWithoutSession = 206
280+
223281
/**
224282
Users can only be created through sign up.
225283
*/
@@ -229,11 +287,22 @@ public struct ParseError: ParseType, Decodable, Swift.Error {
229287
An existing account already linked to another user.
230288
*/
231289
case accountAlreadyLinked = 208
290+
232291
/**
233-
Error code indicating that the current session token is invalid.
292+
The current session token is invalid.
234293
*/
235294
case invalidSessionToken = 209
236295

296+
/**
297+
Error enabling or verifying MFA.
298+
*/
299+
case mfaError = 210
300+
301+
/**
302+
A valid MFA token must be provided.
303+
*/
304+
case mfaTokenRequired = 211
305+
237306
/**
238307
Linked id missing from request.
239308
*/

Tests/ParseSwiftTests/APICommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class APICommandTests: XCTestCase {
142142

143143
//This is less common as the HTTP won't be able to produce ParseErrors directly, but used for testing
144144
func testErrorHTTPReturnsParseError1() {
145-
let originalError = ParseError(code: .invalidServerResponse, message: "Couldn't decode")
145+
let originalError = ParseError(code: .unknownError, message: "Couldn't decode")
146146
MockURLProtocol.mockRequests { _ in
147147
return MockURLResponse(error: originalError)
148148
}

Tests/ParseSwiftTests/ParseCloudTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
165165

166166
func testFunctionError() {
167167

168-
let parseError = ParseError(code: .scriptError, message: "Error: Invalid function")
168+
let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function")
169169

170170
let encoded: Data!
171171
do {
@@ -245,7 +245,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
245245
}
246246

247247
func testFunctionMainQueueError() {
248-
let parseError = ParseError(code: .scriptError, message: "Error: Invalid function")
248+
let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function")
249249

250250
MockURLProtocol.mockRequests { _ in
251251
do {
@@ -322,7 +322,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
322322

323323
func testJobError() {
324324

325-
let parseError = ParseError(code: .scriptError, message: "Error: Invalid function")
325+
let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function")
326326

327327
let encoded: Data!
328328
do {
@@ -402,7 +402,7 @@ class ParseCloudTests: XCTestCase { // swiftlint:disable:this type_body_length
402402
}
403403

404404
func testJobMainQueueError() {
405-
let parseError = ParseError(code: .scriptError, message: "Error: Invalid function")
405+
let parseError = ParseError(code: .scriptFailed, message: "Error: Invalid function")
406406

407407
MockURLProtocol.mockRequests { _ in
408408
do {

0 commit comments

Comments
 (0)