@bzbs/react-api-client 0.2.0 → 0.2.2

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.
package/dist/index.mjs CHANGED
@@ -49,6 +49,14 @@ var BaseService = class {
49
49
  this.baseUrl = baseUrl;
50
50
  }
51
51
  normalizeError(error) {
52
+ if (error.error) {
53
+ return {
54
+ type: "server-error",
55
+ error: error.error,
56
+ statusCode: error.response.status,
57
+ response: error.response
58
+ };
59
+ }
52
60
  if (error.response && error.response.data) {
53
61
  return {
54
62
  type: "server-error",
@@ -74,6 +82,35 @@ var BaseService = class {
74
82
  data
75
83
  };
76
84
  const response = yield this.client.request(__spreadValues({ method, url }, config));
85
+ if (response.status === 204) {
86
+ return { model: "", response, type: "success" };
87
+ }
88
+ if ("Success" in response.data) {
89
+ const data2 = response.data;
90
+ if (data2.Success) {
91
+ if ("Data" in response.data) {
92
+ return { model: data2.Data, response, type: "success" };
93
+ } else {
94
+ return { model: "", response, type: "success" };
95
+ }
96
+ } else {
97
+ const error = {
98
+ type: "server-error",
99
+ error: {
100
+ requestId: response.data.RequestId || "",
101
+ error: {
102
+ id: response.data.Code || 500,
103
+ message: response.data.Message || "An unexpected error occurred.",
104
+ code: response.data.Code || 500,
105
+ type: "buzzebees"
106
+ }
107
+ },
108
+ statusCode: response.data.Code || 500,
109
+ response
110
+ };
111
+ return this.normalizeError(error);
112
+ }
113
+ }
77
114
  return { model: response.data, response, type: "success" };
78
115
  } catch (error) {
79
116
  return this.normalizeError(error);