Hi everyone! I looking for the best way to handle ...
# orm-help
r
Hi everyone! I looking for the best way to handle the
update
error when the entity with a specific
id
doesn't exist. For example, I wrote this function to update one entry of a specific table:
Copy code
updateEntity(_: Subscribed, id: number, data: Prisma.UtilityTypeUpdateInput): Promise<DAORes<UtilityType>>;
updateEntity(_: Subscribed, id: number, ref: Number): Promise<DAORes<UtilityType>>;
async updateEntity(_: Subscribed, id: any, param: any): Promise<DAORes<UtilityType>> {
  try {
    if (typeof param !== 'object') throw new Error('Param type not supported');
      
    const entity = await this.prisma.utilityType.update({ where: { id: id }, data: param });
    return { status: 'UPDATED', entity };
  }
  catch (err) {
    process.env.DEBUG === '1' && console.log(`[ERR]: ${err}`);
    return { status: 'INTERNAL_ERROR', messageKey: 'ErrorUpdateResource' };
  }
}
If
id
doesn't exist in the table the error is correctly catched. Is there a way to had more granularity to the error since the
err
hasn't any code error?