Browse Source

chore(ts): Convert some files/utils useful for api.jsx (#14159)

Alberto Leal 5 years ago
parent
commit
93984b2754

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "@sentry/browser": "5.6.0-beta.4",
     "@sentry/integrations": "5.6.0-beta.4",
     "@sentry/typescript": "^5.3.0",
+    "@types/jquery": "^2.0.53",
     "@types/lodash": "^4.14.134",
     "@types/moment-timezone": "^0.5.12",
     "@types/papaparse": "^4.5.11",

+ 0 - 0
src/sentry/static/sentry/app/constants/apiErrorCodes.jsx → src/sentry/static/sentry/app/constants/apiErrorCodes.tsx


+ 2 - 2
src/sentry/static/sentry/app/utils/guid.jsx → src/sentry/static/sentry/app/utils/guid.tsx

@@ -1,5 +1,5 @@
-export function uniqueId() {
-  const s4 = () => {
+export function uniqueId(): string {
+  const s4 = (): string => {
     return Math.floor((1 + Math.random()) * 0x10000)
       .toString(16)
       .substring(1);

+ 7 - 2
src/sentry/static/sentry/app/utils/requestError/createRequestError.jsx → src/sentry/static/sentry/app/utils/requestError/createRequestError.tsx

@@ -21,8 +21,13 @@ const ERROR_MAP = {
  * @param {Object} resp A XHR response object
  * @param {String} stack The stacktrace to use. Helpful for async calls and we want to preserve a different stack.
  */
-export default function createRequestError(resp, stack, ...args) {
-  const err = new RequestError(...args);
+export default function createRequestError(
+  resp: JQueryXHR,
+  stack: string | undefined,
+  method: 'POST' | 'GET' | 'DELETE' | 'PUT' | undefined,
+  path: string
+) {
+  const err = new RequestError(method, path);
 
   if (resp) {
     const errorName = ERROR_MAP[resp.status];

+ 10 - 6
src/sentry/static/sentry/app/utils/requestError/requestError.jsx → src/sentry/static/sentry/app/utils/requestError/requestError.tsx

@@ -1,5 +1,9 @@
 export default class RequestError extends Error {
-  constructor(method, path) {
+  responseJSON?: any;
+  status?: number;
+  statusText?: string;
+
+  constructor(method: string | undefined, path: string) {
     super(`${method || 'GET'} ${path}`);
     this.name = 'RequestError';
     Object.setPrototypeOf(this, new.target.prototype);
@@ -8,10 +12,10 @@ export default class RequestError extends Error {
   /**
    * Updates Error with XHR response
    */
-  setResponse(resp) {
+  setResponse(resp: JQueryXHR) {
     if (resp) {
       this.setMessage(
-        `${this.message} ${resp.status !== 'undefined' ? resp.status : 'n/a'}`
+        `${this.message} ${typeof resp.status === 'number' ? resp.status : 'n/a'}`
       );
 
       // Some callback handlers expect these properties on the error object
@@ -24,15 +28,15 @@ export default class RequestError extends Error {
     }
   }
 
-  setMessage(message) {
+  setMessage(message: string) {
     this.message = message;
   }
 
-  setStack(newStack) {
+  setStack(newStack: string) {
     this.stack = newStack;
   }
 
-  setName(name) {
+  setName(name: string) {
     this.name = name;
   }
 

+ 5 - 0
yarn.lock

@@ -1706,6 +1706,11 @@
   resolved "https://registry.yarnpkg.com/@types/invariant/-/invariant-2.2.29.tgz#aa845204cd0a289f65d47e0de63a6a815e30cc66"
   integrity sha512-lRVw09gOvgviOfeUrKc/pmTiRZ7g7oDOU6OAutyuSHpm1/o2RaBQvRhgK8QEdu+FFuw/wnWb29A/iuxv9i8OpQ==
 
+"@types/jquery@^2.0.53":
+  version "2.0.53"
+  resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-2.0.53.tgz#89c53bc83d820e50c3b667ae2fdf4276df8b3aba"
+  integrity sha512-MZKPWUhp5TKkoJ/58NSq6io+CSUCOHm2b3Z6U4+r9v70kktB0JM+eRjdp6YmDHtw0kK2XB7L2K7/FMIoziHjUA==
+
 "@types/json5@^0.0.29":
   version "0.0.29"
   resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"