From 1c36e8dac8974631902fb0518c7dc0ecb3c3f0b3 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 30 Oct 2025 10:37:13 +0700 Subject: [PATCH] test try catch avatar profile --- src/controllers/ProfileAvatarController.ts | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index 98db7ca6..c3980c38 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -29,16 +29,26 @@ export class ProfileAvatarController extends Controller { @Get("profileId/{id}") async getProfile(@Path() id: string, @Request() req: RequestWithUser) { - let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_OFFICER"); - if (_workflow == false) - await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id); - const profile = await this.profileRepository.findOne({ - where: { id }, - }); + try { + let _workflow = await new permission().Workflow(req, id, "SYS_REGISTRY_OFFICER"); + if (_workflow == false) + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", id); + const profile = await this.profileRepository.findOne({ + where: { id }, + }); - if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - return new HttpSuccess(profile); + return new HttpSuccess(profile); + } catch (error) { + console.error("Error in getProfile:", error); + + if (error instanceof HttpError) { + throw error; + } + + throw new HttpError(HttpStatus.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาดภายในระบบ"); + } } @Get("profileId-admin/{id}")