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

加载异常处理

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