提交 a3efd245 编写于 作者: KK's avatar KK

加载异常处理

上级 8c74e21f
...@@ -168,18 +168,23 @@ export class ControlServiceBase { ...@@ -168,18 +168,23 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async add(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async add(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let response: HttpResponse; data = this.handleRequestData(action, context, data);
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data); response = await this.service[action](context, data);
} else { } else {
response = await this.service.Create(context, data); response = await this.service.Create(context, data);
} }
if (!response.isError && response.isError()) { if (!response.isError && response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
}
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
await this.onAfterAction(action, context, response);
return response; return response;
} }
...@@ -194,18 +199,24 @@ export class ControlServiceBase { ...@@ -194,18 +199,24 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async delete(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async delete(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let response: HttpResponse; data = this.handleRequestData(action, context, data);
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data); response = await this.service[action](context, data);
} else { } else {
response = await this.service.Remove(context, data); response = await this.service.Remove(context, data);
} }
if (!response.isError && response.isError()) { if (!response.isError && response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
}
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
await this.onAfterAction(action, context, response);
return response; return response;
} }
...@@ -220,18 +231,23 @@ export class ControlServiceBase { ...@@ -220,18 +231,23 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async update(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async update(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let response: HttpResponse; data = this.handleRequestData(action, context, data);
if (Util.isFunction(this.service[action])) { if (Util.isFunction(this.service[action])) {
response = await this.service[action](context, data); response = await this.service[action](context, data);
} else { } else {
response = await this.service.Update(context, data); response = await this.service.Update(context, data);
} }
if (!response.isError && response.isError()) { if (!response.isError && response.isError()) {
response = this.handleResponse(action, response); response = this.handleResponse(action, response);
}
}catch(error){
console.error(error)
}finally{
await this.onAfterAction(action, context, response);
} }
await this.onAfterAction(action, context, response);
return response; return response;
} }
...@@ -246,18 +262,24 @@ export class ControlServiceBase { ...@@ -246,18 +262,24 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async get(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async get(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let response: HttpResponse; data = this.handleRequestData(action, context, data);
if (Util.isFunction(this.service[action])) { let response: HttpResponse;
response = await this.service[action](context, data); if (Util.isFunction(this.service[action])) {
} else { response = await this.service[action](context, data);
response = await this.service.Get(context, data); } else {
} response = await this.service.Get(context, data);
if (!response.isError && response.isError()) { }
response = this.handleResponse(action, response); if (!response.isError && response.isError()) {
response = this.handleResponse(action, response);
}
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
await this.onAfterAction(action, context, response);
return response; return response;
} }
...@@ -272,24 +294,32 @@ export class ControlServiceBase { ...@@ -272,24 +294,32 @@ export class ControlServiceBase {
* @memberof ControlServiceBase * @memberof ControlServiceBase
*/ */
public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async loadDraft(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let PrimaryKey = Util.createUUID();
//仿真主键数据 data = this.handleRequestData(action, context, data);
data[this.appDeKey] = PrimaryKey; let PrimaryKey = Util.createUUID();
let response: HttpResponse; //仿真主键数据
if (Util.isFunction(this.service[action])) { data[this.appDeKey] = PrimaryKey;
response = await this.service[action](context, data); let response: HttpResponse;
} else { if (Util.isFunction(this.service[action])) {
response = await this.service.GetDraft(context, data); response = await this.service[action](context, data);
} } else {
if (!response.isError && response.isError()) { response = await this.service.GetDraft(context, data);
response = this.handleResponse(action, response, true); }
this.mergeDefaults(response); if (!response.isError && response.isError()) {
response = this.handleResponse(action, response, true);
this.mergeDefaults(response);
}
response.data[this.appDeKey] = PrimaryKey;
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
response.data[this.appDeKey] = PrimaryKey;
await this.onAfterAction(action, context, response);
return response; return response;
} }
/** /**
...@@ -302,18 +332,24 @@ export class ControlServiceBase { ...@@ -302,18 +332,24 @@ export class ControlServiceBase {
* @memberof EditServiceBase * @memberof EditServiceBase
*/ */
public async frontLogic(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> { public async frontLogic(action: string, context: any = {}, data: any = {}, isLoading?: boolean): Promise<HttpResponse> {
let response: HttpResponse = null as any;
await this.onBeforeAction(action, context, data, isLoading); await this.onBeforeAction(action, context, data, isLoading);
data = this.handleRequestData(action, context, data); try{
let response: HttpResponse; data = this.handleRequestData(action, context, data);
if (Util.isFunction(this.service[action])) { let response: HttpResponse;
response = await this.service[action](context, data); if (Util.isFunction(this.service[action])) {
} else { response = await this.service[action](context, data);
response = new HttpResponse(200, null, { code: 100, message: `${action}前台逻辑未实现` }); } else {
} response = new HttpResponse(200, null, { code: 100, message: `${action}前台逻辑未实现` });
if (!response.isError && response.isError()) { }
response = this.handleResponse(action, response, true); if (!response.isError && response.isError()) {
response = this.handleResponse(action, response, true);
}
}catch (error) {
console.error(error);
}finally{
await this.onAfterAction(action, context, response);
} }
await this.onAfterAction(action, context, response);
return response; return response;
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册