ParseError.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. "use strict";
  2. var _Object$defineProperty2 = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  3. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  4. _Object$defineProperty2(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.default = void 0;
  8. var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
  9. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
  10. var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
  11. var _CoreManager = _interopRequireDefault(require("./CoreManager"));
  12. /**
  13. * Constructs a new Parse.Error object with the given code and message.
  14. *
  15. * Parse.CoreManager.set('PARSE_ERRORS', [{ code, message }]) can be use to override error messages.
  16. *
  17. * @alias Parse.Error
  18. */
  19. class ParseError extends Error {
  20. /**
  21. * @param {number} code An error code constant from <code>Parse.Error</code>.
  22. * @param {string} message A detailed description of the error.
  23. */
  24. constructor(code, message) {
  25. var _context;
  26. super(message);
  27. (0, _defineProperty3.default)(this, "code", void 0);
  28. (0, _defineProperty3.default)(this, "message", void 0);
  29. (0, _defineProperty3.default)(this, "object", void 0);
  30. (0, _defineProperty3.default)(this, "errors", void 0);
  31. this.code = code;
  32. let customMessage = message;
  33. (0, _forEach.default)(_context = _CoreManager.default.get('PARSE_ERRORS')).call(_context, error => {
  34. if (error.code === code && error.code) {
  35. customMessage = error.message;
  36. }
  37. });
  38. (0, _defineProperty2.default)(this, 'message', {
  39. enumerable: true,
  40. value: customMessage
  41. });
  42. }
  43. toString() {
  44. return 'ParseError: ' + this.code + ' ' + this.message;
  45. }
  46. /**
  47. * Error code indicating some error other than those enumerated here.
  48. *
  49. * @property {number} OTHER_CAUSE
  50. * @static
  51. */
  52. }
  53. (0, _defineProperty3.default)(ParseError, "OTHER_CAUSE", -1);
  54. /**
  55. * Error code indicating that something has gone wrong with the server.
  56. *
  57. * @property {number} INTERNAL_SERVER_ERROR
  58. * @static
  59. */
  60. (0, _defineProperty3.default)(ParseError, "INTERNAL_SERVER_ERROR", 1);
  61. /**
  62. * Error code indicating the connection to the Parse servers failed.
  63. *
  64. * @property {number} CONNECTION_FAILED
  65. * @static
  66. */
  67. (0, _defineProperty3.default)(ParseError, "CONNECTION_FAILED", 100);
  68. /**
  69. * Error code indicating the specified object doesn't exist.
  70. *
  71. * @property {number} OBJECT_NOT_FOUND
  72. * @static
  73. */
  74. (0, _defineProperty3.default)(ParseError, "OBJECT_NOT_FOUND", 101);
  75. /**
  76. * Error code indicating you tried to query with a datatype that doesn't
  77. * support it, like exact matching an array or object.
  78. *
  79. * @property {number} INVALID_QUERY
  80. * @static
  81. */
  82. (0, _defineProperty3.default)(ParseError, "INVALID_QUERY", 102);
  83. /**
  84. * Error code indicating a missing or invalid classname. Classnames are
  85. * case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the
  86. * only valid characters.
  87. *
  88. * @property {number} INVALID_CLASS_NAME
  89. * @static
  90. */
  91. (0, _defineProperty3.default)(ParseError, "INVALID_CLASS_NAME", 103);
  92. /**
  93. * Error code indicating an unspecified object id.
  94. *
  95. * @property {number} MISSING_OBJECT_ID
  96. * @static
  97. */
  98. (0, _defineProperty3.default)(ParseError, "MISSING_OBJECT_ID", 104);
  99. /**
  100. * Error code indicating an invalid key name. Keys are case-sensitive. They
  101. * must start with a letter, and a-zA-Z0-9_ are the only valid characters.
  102. *
  103. * @property {number} INVALID_KEY_NAME
  104. * @static
  105. */
  106. (0, _defineProperty3.default)(ParseError, "INVALID_KEY_NAME", 105);
  107. /**
  108. * Error code indicating a malformed pointer. You should not see this unless
  109. * you have been mucking about changing internal Parse code.
  110. *
  111. * @property {number} INVALID_POINTER
  112. * @static
  113. */
  114. (0, _defineProperty3.default)(ParseError, "INVALID_POINTER", 106);
  115. /**
  116. * Error code indicating that badly formed JSON was received upstream. This
  117. * either indicates you have done something unusual with modifying how
  118. * things encode to JSON, or the network is failing badly.
  119. *
  120. * @property {number} INVALID_JSON
  121. * @static
  122. */
  123. (0, _defineProperty3.default)(ParseError, "INVALID_JSON", 107);
  124. /**
  125. * Error code indicating that the feature you tried to access is only
  126. * available internally for testing purposes.
  127. *
  128. * @property {number} COMMAND_UNAVAILABLE
  129. * @static
  130. */
  131. (0, _defineProperty3.default)(ParseError, "COMMAND_UNAVAILABLE", 108);
  132. /**
  133. * You must call Parse.initialize before using the Parse library.
  134. *
  135. * @property {number} NOT_INITIALIZED
  136. * @static
  137. */
  138. (0, _defineProperty3.default)(ParseError, "NOT_INITIALIZED", 109);
  139. /**
  140. * Error code indicating that a field was set to an inconsistent type.
  141. *
  142. * @property {number} INCORRECT_TYPE
  143. * @static
  144. */
  145. (0, _defineProperty3.default)(ParseError, "INCORRECT_TYPE", 111);
  146. /**
  147. * Error code indicating an invalid channel name. A channel name is either
  148. * an empty string (the broadcast channel) or contains only a-zA-Z0-9_
  149. * characters and starts with a letter.
  150. *
  151. * @property {number} INVALID_CHANNEL_NAME
  152. * @static
  153. */
  154. (0, _defineProperty3.default)(ParseError, "INVALID_CHANNEL_NAME", 112);
  155. /**
  156. * Error code indicating that push is misconfigured.
  157. *
  158. * @property {number} PUSH_MISCONFIGURED
  159. * @static
  160. */
  161. (0, _defineProperty3.default)(ParseError, "PUSH_MISCONFIGURED", 115);
  162. /**
  163. * Error code indicating that the object is too large.
  164. *
  165. * @property {number} OBJECT_TOO_LARGE
  166. * @static
  167. */
  168. (0, _defineProperty3.default)(ParseError, "OBJECT_TOO_LARGE", 116);
  169. /**
  170. * Error code indicating that the operation isn't allowed for clients.
  171. *
  172. * @property {number} OPERATION_FORBIDDEN
  173. * @static
  174. */
  175. (0, _defineProperty3.default)(ParseError, "OPERATION_FORBIDDEN", 119);
  176. /**
  177. * Error code indicating the result was not found in the cache.
  178. *
  179. * @property {number} CACHE_MISS
  180. * @static
  181. */
  182. (0, _defineProperty3.default)(ParseError, "CACHE_MISS", 120);
  183. /**
  184. * Error code indicating that an invalid key was used in a nested
  185. * JSONObject.
  186. *
  187. * @property {number} INVALID_NESTED_KEY
  188. * @static
  189. */
  190. (0, _defineProperty3.default)(ParseError, "INVALID_NESTED_KEY", 121);
  191. /**
  192. * Error code indicating that an invalid filename was used for ParseFile.
  193. * A valid file name contains only a-zA-Z0-9_. characters and is between 1
  194. * and 128 characters.
  195. *
  196. * @property {number} INVALID_FILE_NAME
  197. * @static
  198. */
  199. (0, _defineProperty3.default)(ParseError, "INVALID_FILE_NAME", 122);
  200. /**
  201. * Error code indicating an invalid ACL was provided.
  202. *
  203. * @property {number} INVALID_ACL
  204. * @static
  205. */
  206. (0, _defineProperty3.default)(ParseError, "INVALID_ACL", 123);
  207. /**
  208. * Error code indicating that the request timed out on the server. Typically
  209. * this indicates that the request is too expensive to run.
  210. *
  211. * @property {number} TIMEOUT
  212. * @static
  213. */
  214. (0, _defineProperty3.default)(ParseError, "TIMEOUT", 124);
  215. /**
  216. * Error code indicating that the email address was invalid.
  217. *
  218. * @property {number} INVALID_EMAIL_ADDRESS
  219. * @static
  220. */
  221. (0, _defineProperty3.default)(ParseError, "INVALID_EMAIL_ADDRESS", 125);
  222. /**
  223. * Error code indicating a missing content type.
  224. *
  225. * @property {number} MISSING_CONTENT_TYPE
  226. * @static
  227. */
  228. (0, _defineProperty3.default)(ParseError, "MISSING_CONTENT_TYPE", 126);
  229. /**
  230. * Error code indicating a missing content length.
  231. *
  232. * @property {number} MISSING_CONTENT_LENGTH
  233. * @static
  234. */
  235. (0, _defineProperty3.default)(ParseError, "MISSING_CONTENT_LENGTH", 127);
  236. /**
  237. * Error code indicating an invalid content length.
  238. *
  239. * @property {number} INVALID_CONTENT_LENGTH
  240. * @static
  241. */
  242. (0, _defineProperty3.default)(ParseError, "INVALID_CONTENT_LENGTH", 128);
  243. /**
  244. * Error code indicating a file that was too large.
  245. *
  246. * @property {number} FILE_TOO_LARGE
  247. * @static
  248. */
  249. (0, _defineProperty3.default)(ParseError, "FILE_TOO_LARGE", 129);
  250. /**
  251. * Error code indicating an error saving a file.
  252. *
  253. * @property {number} FILE_SAVE_ERROR
  254. * @static
  255. */
  256. (0, _defineProperty3.default)(ParseError, "FILE_SAVE_ERROR", 130);
  257. /**
  258. * Error code indicating that a unique field was given a value that is
  259. * already taken.
  260. *
  261. * @property {number} DUPLICATE_VALUE
  262. * @static
  263. */
  264. (0, _defineProperty3.default)(ParseError, "DUPLICATE_VALUE", 137);
  265. /**
  266. * Error code indicating that a role's name is invalid.
  267. *
  268. * @property {number} INVALID_ROLE_NAME
  269. * @static
  270. */
  271. (0, _defineProperty3.default)(ParseError, "INVALID_ROLE_NAME", 139);
  272. /**
  273. * Error code indicating that an application quota was exceeded. Upgrade to
  274. * resolve.
  275. *
  276. * @property {number} EXCEEDED_QUOTA
  277. * @static
  278. */
  279. (0, _defineProperty3.default)(ParseError, "EXCEEDED_QUOTA", 140);
  280. /**
  281. * Error code indicating that a Cloud Code script failed.
  282. *
  283. * @property {number} SCRIPT_FAILED
  284. * @static
  285. */
  286. (0, _defineProperty3.default)(ParseError, "SCRIPT_FAILED", 141);
  287. /**
  288. * Error code indicating that a Cloud Code validation failed.
  289. *
  290. * @property {number} VALIDATION_ERROR
  291. * @static
  292. */
  293. (0, _defineProperty3.default)(ParseError, "VALIDATION_ERROR", 142);
  294. /**
  295. * Error code indicating that invalid image data was provided.
  296. *
  297. * @property {number} INVALID_IMAGE_DATA
  298. * @static
  299. */
  300. (0, _defineProperty3.default)(ParseError, "INVALID_IMAGE_DATA", 143);
  301. /**
  302. * Error code indicating an unsaved file.
  303. *
  304. * @property {number} UNSAVED_FILE_ERROR
  305. * @static
  306. */
  307. (0, _defineProperty3.default)(ParseError, "UNSAVED_FILE_ERROR", 151);
  308. /**
  309. * Error code indicating an invalid push time.
  310. *
  311. * @property {number} INVALID_PUSH_TIME_ERROR
  312. * @static
  313. */
  314. (0, _defineProperty3.default)(ParseError, "INVALID_PUSH_TIME_ERROR", 152);
  315. /**
  316. * Error code indicating an error deleting a file.
  317. *
  318. * @property {number} FILE_DELETE_ERROR
  319. * @static
  320. */
  321. (0, _defineProperty3.default)(ParseError, "FILE_DELETE_ERROR", 153);
  322. /**
  323. * Error code indicating an error deleting an unnamed file.
  324. *
  325. * @property {number} FILE_DELETE_UNNAMED_ERROR
  326. * @static
  327. */
  328. (0, _defineProperty3.default)(ParseError, "FILE_DELETE_UNNAMED_ERROR", 161);
  329. /**
  330. * Error code indicating that the application has exceeded its request
  331. * limit.
  332. *
  333. * @property {number} REQUEST_LIMIT_EXCEEDED
  334. * @static
  335. */
  336. (0, _defineProperty3.default)(ParseError, "REQUEST_LIMIT_EXCEEDED", 155);
  337. /**
  338. * Error code indicating that the request was a duplicate and has been discarded due to
  339. * idempotency rules.
  340. *
  341. * @property {number} DUPLICATE_REQUEST
  342. * @static
  343. */
  344. (0, _defineProperty3.default)(ParseError, "DUPLICATE_REQUEST", 159);
  345. /**
  346. * Error code indicating an invalid event name.
  347. *
  348. * @property {number} INVALID_EVENT_NAME
  349. * @static
  350. */
  351. (0, _defineProperty3.default)(ParseError, "INVALID_EVENT_NAME", 160);
  352. /**
  353. * Error code indicating that a field had an invalid value.
  354. *
  355. * @property {number} INVALID_VALUE
  356. * @static
  357. */
  358. (0, _defineProperty3.default)(ParseError, "INVALID_VALUE", 162);
  359. /**
  360. * Error code indicating that the username is missing or empty.
  361. *
  362. * @property {number} USERNAME_MISSING
  363. * @static
  364. */
  365. (0, _defineProperty3.default)(ParseError, "USERNAME_MISSING", 200);
  366. /**
  367. * Error code indicating that the password is missing or empty.
  368. *
  369. * @property {number} PASSWORD_MISSING
  370. * @static
  371. */
  372. (0, _defineProperty3.default)(ParseError, "PASSWORD_MISSING", 201);
  373. /**
  374. * Error code indicating that the username has already been taken.
  375. *
  376. * @property {number} USERNAME_TAKEN
  377. * @static
  378. */
  379. (0, _defineProperty3.default)(ParseError, "USERNAME_TAKEN", 202);
  380. /**
  381. * Error code indicating that the email has already been taken.
  382. *
  383. * @property {number} EMAIL_TAKEN
  384. * @static
  385. */
  386. (0, _defineProperty3.default)(ParseError, "EMAIL_TAKEN", 203);
  387. /**
  388. * Error code indicating that the email is missing, but must be specified.
  389. *
  390. * @property {number} EMAIL_MISSING
  391. * @static
  392. */
  393. (0, _defineProperty3.default)(ParseError, "EMAIL_MISSING", 204);
  394. /**
  395. * Error code indicating that a user with the specified email was not found.
  396. *
  397. * @property {number} EMAIL_NOT_FOUND
  398. * @static
  399. */
  400. (0, _defineProperty3.default)(ParseError, "EMAIL_NOT_FOUND", 205);
  401. /**
  402. * Error code indicating that a user object without a valid session could
  403. * not be altered.
  404. *
  405. * @property {number} SESSION_MISSING
  406. * @static
  407. */
  408. (0, _defineProperty3.default)(ParseError, "SESSION_MISSING", 206);
  409. /**
  410. * Error code indicating that a user can only be created through signup.
  411. *
  412. * @property {number} MUST_CREATE_USER_THROUGH_SIGNUP
  413. * @static
  414. */
  415. (0, _defineProperty3.default)(ParseError, "MUST_CREATE_USER_THROUGH_SIGNUP", 207);
  416. /**
  417. * Error code indicating that an an account being linked is already linked
  418. * to another user.
  419. *
  420. * @property {number} ACCOUNT_ALREADY_LINKED
  421. * @static
  422. */
  423. (0, _defineProperty3.default)(ParseError, "ACCOUNT_ALREADY_LINKED", 208);
  424. /**
  425. * Error code indicating that the current session token is invalid.
  426. *
  427. * @property {number} INVALID_SESSION_TOKEN
  428. * @static
  429. */
  430. (0, _defineProperty3.default)(ParseError, "INVALID_SESSION_TOKEN", 209);
  431. /**
  432. * Error code indicating an error enabling or verifying MFA
  433. *
  434. * @property {number} MFA_ERROR
  435. * @static
  436. */
  437. (0, _defineProperty3.default)(ParseError, "MFA_ERROR", 210);
  438. /**
  439. * Error code indicating that a valid MFA token must be provided
  440. *
  441. * @property {number} MFA_TOKEN_REQUIRED
  442. * @static
  443. */
  444. (0, _defineProperty3.default)(ParseError, "MFA_TOKEN_REQUIRED", 211);
  445. /**
  446. * Error code indicating that a user cannot be linked to an account because
  447. * that account's id could not be found.
  448. *
  449. * @property {number} LINKED_ID_MISSING
  450. * @static
  451. */
  452. (0, _defineProperty3.default)(ParseError, "LINKED_ID_MISSING", 250);
  453. /**
  454. * Error code indicating that a user with a linked (e.g. Facebook) account
  455. * has an invalid session.
  456. *
  457. * @property {number} INVALID_LINKED_SESSION
  458. * @static
  459. */
  460. (0, _defineProperty3.default)(ParseError, "INVALID_LINKED_SESSION", 251);
  461. /**
  462. * Error code indicating that a service being linked (e.g. Facebook or
  463. * Twitter) is unsupported.
  464. *
  465. * @property {number} UNSUPPORTED_SERVICE
  466. * @static
  467. */
  468. (0, _defineProperty3.default)(ParseError, "UNSUPPORTED_SERVICE", 252);
  469. /**
  470. * Error code indicating an invalid operation occured on schema
  471. *
  472. * @property {number} INVALID_SCHEMA_OPERATION
  473. * @static
  474. */
  475. (0, _defineProperty3.default)(ParseError, "INVALID_SCHEMA_OPERATION", 255);
  476. /**
  477. * Error code indicating that there were multiple errors. Aggregate errors
  478. * have an "errors" property, which is an array of error objects with more
  479. * detail about each error that occurred.
  480. *
  481. * @property {number} AGGREGATE_ERROR
  482. * @static
  483. */
  484. (0, _defineProperty3.default)(ParseError, "AGGREGATE_ERROR", 600);
  485. /**
  486. * Error code indicating the client was unable to read an input file.
  487. *
  488. * @property {number} FILE_READ_ERROR
  489. * @static
  490. */
  491. (0, _defineProperty3.default)(ParseError, "FILE_READ_ERROR", 601);
  492. /**
  493. * Error code indicating a real error code is unavailable because
  494. * we had to use an XDomainRequest object to allow CORS requests in
  495. * Internet Explorer, which strips the body from HTTP responses that have
  496. * a non-2XX status code.
  497. *
  498. * @property {number} X_DOMAIN_REQUEST
  499. * @static
  500. */
  501. (0, _defineProperty3.default)(ParseError, "X_DOMAIN_REQUEST", 602);
  502. var _default = exports.default = ParseError;