jordy 0.20.6 → 0.20.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,10 +15,10 @@ export function ErrorParser(throwableParser) {
15
15
  args[_i] = arguments[_i];
16
16
  }
17
17
  var _this = this;
18
- this.parse = function (error) { return __awaiter(_this, void 0, void 0, function () {
18
+ this.parse = function (error, method, url) { return __awaiter(_this, void 0, void 0, function () {
19
19
  var nextError;
20
20
  return __generator(this, function (_a) {
21
- nextError = throwableParser(error);
21
+ nextError = throwableParser(error, method, url);
22
22
  if (nextError) {
23
23
  throw nextError;
24
24
  }
@@ -29,58 +29,64 @@ export function ErrorParser(throwableParser) {
29
29
  this.network = new ClassConstructor(args[0], args[1], args[2]);
30
30
  }
31
31
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.get = function () {
32
+ var _this = this;
32
33
  var args = [];
33
34
  for (var _i = 0; _i < arguments.length; _i++) {
34
35
  args[_i] = arguments[_i];
35
36
  }
36
37
  return this.network.get
37
38
  .apply(this.network, __spreadArray([], __read(args), false))
38
- .catch(this.parse);
39
+ .catch(function (err) { return _this.parse(err, 'get', args[0]); });
39
40
  };
40
41
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.post = function () {
42
+ var _this = this;
41
43
  var args = [];
42
44
  for (var _i = 0; _i < arguments.length; _i++) {
43
45
  args[_i] = arguments[_i];
44
46
  }
45
47
  return this.network.post
46
48
  .apply(this.network, __spreadArray([], __read(args), false))
47
- .catch(this.parse);
49
+ .catch(function (err) { return _this.parse(err, 'post', args[0]); });
48
50
  };
49
51
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.put = function () {
52
+ var _this = this;
50
53
  var args = [];
51
54
  for (var _i = 0; _i < arguments.length; _i++) {
52
55
  args[_i] = arguments[_i];
53
56
  }
54
57
  return this.network.put
55
58
  .apply(this.network, __spreadArray([], __read(args), false))
56
- .catch(this.parse);
59
+ .catch(function (err) { return _this.parse(err, 'put', args[0]); });
57
60
  };
58
61
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.patch = function () {
62
+ var _this = this;
59
63
  var args = [];
60
64
  for (var _i = 0; _i < arguments.length; _i++) {
61
65
  args[_i] = arguments[_i];
62
66
  }
63
67
  return this.network.patch
64
68
  .apply(this.network, __spreadArray([], __read(args), false))
65
- .catch(this.parse);
69
+ .catch(function (err) { return _this.parse(err, 'patch', args[0]); });
66
70
  };
67
71
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.delete = function () {
72
+ var _this = this;
68
73
  var args = [];
69
74
  for (var _i = 0; _i < arguments.length; _i++) {
70
75
  args[_i] = arguments[_i];
71
76
  }
72
77
  return this.network.delete
73
78
  .apply(this.network, __spreadArray([], __read(args), false))
74
- .catch(this.parse);
79
+ .catch(function (err) { return _this.parse(err, 'delete', args[0]); });
75
80
  };
76
81
  ErrorParserDecoratedUnionHttpNetworkProvider.prototype.getBlob = function () {
82
+ var _this = this;
77
83
  var args = [];
78
84
  for (var _i = 0; _i < arguments.length; _i++) {
79
85
  args[_i] = arguments[_i];
80
86
  }
81
87
  return this.network.getBlob
82
88
  .apply(this.network, __spreadArray([], __read(args), false))
83
- .catch(this.parse);
89
+ .catch(function (err) { return _this.parse(err, 'get', args[0]); });
84
90
  };
85
91
  return ErrorParserDecoratedUnionHttpNetworkProvider;
86
92
  }());
@@ -29,7 +29,9 @@ var HttpRestError = (function () {
29
29
  if (typeof arg !== 'string' && arg) {
30
30
  this.url = arg.url || '';
31
31
  this.method = arg.method;
32
- this.errorType = this.toErrorType(Number(arg.status));
32
+ this.errorType = arg.errorType
33
+ ? arg.errorType
34
+ : this.toErrorType(Number(arg.status));
33
35
  this.rawData = arg.rawData;
34
36
  }
35
37
  };
@@ -63,6 +65,17 @@ var HttpRestError = (function () {
63
65
  }
64
66
  return 'unknown';
65
67
  };
68
+ HttpRestError.toStatusCodeFrom = function (type) {
69
+ var dic = {
70
+ auth: 401,
71
+ forbidden: 403,
72
+ notFound: 404,
73
+ server: 500,
74
+ badRequest: 400,
75
+ unknown: 0,
76
+ };
77
+ return dic[type];
78
+ };
66
79
  HttpRestError.isHttpRestErrorType = function (value) {
67
80
  var dic = {
68
81
  unknown: true,
@@ -1,20 +1,20 @@
1
1
  import { HttpRestError } from '../HttpRestError';
2
2
  import { isAxiosError } from './axios.util';
3
- function tryGetMethod(method) {
3
+ function tryGetMethod(method, def) {
4
4
  try {
5
- return method.toLocaleLowerCase();
5
+ return (method.toLocaleLowerCase() || def);
6
6
  }
7
7
  catch (error) {
8
- return undefined;
8
+ return def;
9
9
  }
10
10
  }
11
- export function throwableAxiosErrorParser(error) {
11
+ export function throwableAxiosErrorParser(error, method, url) {
12
12
  var _a, _b;
13
13
  if (isAxiosError(error)) {
14
14
  var errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
15
15
  var meta = {
16
- url: error.config.url || '',
17
- method: tryGetMethod(error.config.method),
16
+ url: error.config.url || url,
17
+ method: tryGetMethod(error.config.method, method),
18
18
  status: Number(((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || 0),
19
19
  rawData: errorData,
20
20
  };
@@ -29,4 +29,25 @@ export function throwableAxiosErrorParser(error) {
29
29
  }
30
30
  throw new HttpRestError(HttpRestError.DEFAULT_MESSAGE, meta);
31
31
  }
32
+ if (method && url) {
33
+ if (HttpRestError.isHttpRestErrorLike(error)) {
34
+ throw new HttpRestError(error.message, {
35
+ method: error.method || method,
36
+ url: error.url || url,
37
+ status: HttpRestError.toStatusCodeFrom(error.errorType),
38
+ errorType: error.errorType,
39
+ rawData: error.rawData,
40
+ });
41
+ }
42
+ var meta = {
43
+ method: method,
44
+ url: url,
45
+ status: 0,
46
+ rawData: error,
47
+ };
48
+ if (HttpRestError.isErrorLike(error)) {
49
+ throw new HttpRestError(error.message, meta);
50
+ }
51
+ throw new HttpRestError(HttpRestError.DEFAULT_MESSAGE, meta);
52
+ }
32
53
  }
@@ -1,3 +1,4 @@
1
+ import { RestHttpMethodType } from './network.type';
1
2
  declare type ConstructorType = {
2
3
  new (...args: any[]): any;
3
4
  };
@@ -15,5 +16,5 @@ declare type ConstructorType = {
15
16
  * @see AsyncHttpNetworkProvider
16
17
  * @see AsyncHttpUploadProvider
17
18
  */
18
- export declare function ErrorParser<E = any>(throwableParser: (error: E) => any): <C extends ConstructorType>(ClassConstructor: C) => C;
19
+ export declare function ErrorParser<E = any>(throwableParser: (error: E, method: RestHttpMethodType, url: string) => any): <C extends ConstructorType>(ClassConstructor: C) => C;
19
20
  export {};
@@ -13,7 +13,8 @@ export interface HttpRestErrorMetaArgs {
13
13
  url: string;
14
14
  method?: RestHttpMethodType;
15
15
  rawData: any;
16
- status: number;
16
+ status?: number;
17
+ errorType?: HttpRestErrorType;
17
18
  }
18
19
  export interface HttpRestErrorLike extends ErrorLike, HttpRestErrorMeta {
19
20
  }
@@ -36,6 +37,7 @@ export declare class HttpRestError implements Error, HttpRestErrorLike {
36
37
  toPlainObject(): HttpRestErrorLike;
37
38
  toString(): string;
38
39
  toErrorType(status: number): HttpRestErrorType;
40
+ static toStatusCodeFrom(type: HttpRestErrorType): number;
39
41
  static isHttpRestErrorType(value: unknown): value is HttpRestErrorType;
40
42
  static isErrorLike(error: unknown): error is ErrorLike;
41
43
  static isHttpRestErrorLike(error: unknown): error is HttpRestErrorLike;
@@ -1 +1,2 @@
1
- export declare function throwableAxiosErrorParser(error: any): void;
1
+ import { RestHttpMethodType } from '../network.type';
2
+ export declare function throwableAxiosErrorParser(error: any, method: RestHttpMethodType, url: string): void;
@@ -31,6 +31,8 @@ export interface JWTProvider {
31
31
  set(tokenValue: JWTAuthTokenDto): void;
32
32
  /**
33
33
  * 엑세스 토큰값을 가져온다.
34
+ *
35
+ * @throws 가져오는데 실패 했다면 오류를 일으킨다.
34
36
  */
35
37
  get(): Promise<string>;
36
38
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jordy",
3
- "version": "0.20.6",
3
+ "version": "0.20.7",
4
4
  "description": "typescript based frontend toolkit",
5
5
  "repository": {
6
6
  "type": "git",