@dile/crud 0.0.67 → 0.0.68

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.
@@ -10,6 +10,7 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
10
10
  url: { type: String },
11
11
  statusSuccessCodes: { type: Array },
12
12
  sendDataAsFormData: { type: Boolean },
13
+ getValidationErrors: { type: Object },
13
14
  }
14
15
  }
15
16
 
@@ -18,6 +19,9 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
18
19
  this.method = 'post';
19
20
  this.url = '';
20
21
  this.statusSuccessCodes = [200, 201];
22
+ this.getValidationErrors = (data) => {
23
+ return data.errors
24
+ }
21
25
  }
22
26
 
23
27
  get computedData() {
@@ -52,17 +56,13 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
52
56
  break
53
57
  }
54
58
  request.then((response) => {
59
+ this.dispatchResponse(response)
55
60
  if(this.statusSuccessCodes.includes(response.status)) {
56
- let res = response.data;
57
- if(res.error) {
58
- this.dispatchError(res.data);
59
- } else {
60
- this.dispatchEvent(new CustomEvent('ajax-success', {
61
- detail: res
62
- }));
63
- }
61
+ this.dispatchEvent(new CustomEvent('ajax-success', {
62
+ detail: response.data
63
+ }));
64
64
  } else {
65
- this.dispatchError(this.translations.http_unhandled_success);
65
+ this.dispatchError(this.translations.http_unhandled_success, response.data);
66
66
  }
67
67
  })
68
68
  .catch(err => {
@@ -75,54 +75,64 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
75
75
 
76
76
  describeError(err) {
77
77
  if (err.response) {
78
- const status = err.response.status;
78
+ const res = err.response;
79
+ const status = res.status;
79
80
  switch (status) {
80
81
  case 422:
81
82
  case 400:
82
- this.dispatchError(err.response.data.message, err.response.data.errors);
83
+ this.dispatchError(res.data.message, res.data, this.getValidationErrors(res.data));
83
84
  break;
84
85
  case 404:
85
- if(err.response.data.message) {
86
- this.dispatchError(err.response.data.message);
86
+ if(res.data.message) {
87
+ this.dispatchError(res.data.message, res.data);
87
88
  } else {
88
- this.dispatchError(this.translations.http_404);
89
+ this.dispatchError(this.translations.http_404, res.data);
89
90
  }
90
91
  break;
91
92
  case 401:
92
- this.dispatchError(this.translations.http_401);
93
+ this.dispatchError(this.translations.http_401, res.data);
93
94
  break;
94
95
  case 405:
95
- this.dispatchError(this.translations.http_405);
96
+ this.dispatchError(this.translations.http_405, res.data);
96
97
  break;
97
98
  case 413:
98
- this.dispatchError(this.translations.http_413);
99
+ this.dispatchError(this.translations.http_413, res.data);
99
100
  break;
100
101
  case 419:
101
- this.dispatchError(this.translations.http_419);
102
+ this.dispatchError(this.translations.http_419, res.data);
102
103
  break;
103
104
  case 502:
104
- this.dispatchError(this.translations.http_502);
105
+ this.dispatchError(this.translations.http_502, res.data);
105
106
  break;
106
107
  case 504:
107
- this.dispatchError(this.translations.http_504);
108
+ this.dispatchError(this.translations.http_504, res.data);
108
109
  break;
109
110
  default:
110
- this.dispatchError(this.translations.http_other_error);
111
+ this.dispatchError(this.translations.http_other_error, res.data);
111
112
  }
112
113
  } else {
113
- this.dispatchError(this.translations.http_no_response);
114
+ this.dispatchError(this.translations.http_no_response, {});
114
115
  }
115
116
  }
116
117
 
117
- dispatchError(message, errors = []) {
118
+ dispatchError(message, data, errors = []) {
118
119
  this.dispatchEvent(new CustomEvent('ajax-error', {
119
120
  detail: {
120
121
  message,
122
+ data,
121
123
  errors
122
124
  }
123
125
  }));
124
126
  }
125
127
 
128
+ dispatchResponse(response) {
129
+ this.dispatchEvent(new CustomEvent('ajax-response', {
130
+ detail: {
131
+ response
132
+ }
133
+ }));
134
+ }
135
+
126
136
  _prepareFormData() {
127
137
  this._createFormData();
128
138
  this._addObjectToFormData(this.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "30f2fe016bd36491891ce254bc97590e1fc17d19"
34
+ "gitHead": "98d572545dae6e89cda4f2240bc0e5caface20e0"
35
35
  }