fixing throw error & message error

This commit is contained in:
Warunee Tamkoo 2025-04-09 23:47:55 +07:00
parent 488b3b0923
commit da710215ec

View file

@ -63,12 +63,12 @@ export class DocumentController extends Controller {
public async getFile(@Path() volume: string, @Path() id: string) {
try {
const list = await listFile(["ระบบประเมิน", volume, id]);
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอ่านแฟ้มได้");
return list;
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
@ -108,12 +108,12 @@ export class DocumentController extends Controller {
public async getFileDownload(@Path() id: string, @Path() volume: string, @Path() file: string) {
try {
const data = await downloadFile(["ระบบประเมิน", volume, id], file);
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถดาวน์โหลดไฟล์ได้");
return data;
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
@ -219,7 +219,7 @@ export class DocumentController extends Controller {
const list = await listFile(["ระบบประเมิน", volume, id]);
if (!list || !Array.isArray(list)) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอ่านแฟ้มได้");
}
// let used: string[] = [];
@ -299,7 +299,7 @@ export class DocumentController extends Controller {
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
@ -336,7 +336,7 @@ export class DocumentController extends Controller {
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
@ -358,7 +358,7 @@ export class DocumentController extends Controller {
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
@ -375,13 +375,13 @@ export class DocumentController extends Controller {
const result = await deleteFile(["ระบบประเมิน", volume, id], file);
if (!result) {
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้");
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถลบไฟล์ได้");
}
return this.setStatus(HttpStatus.NO_CONTENT);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
}
}