I'm trying to handle exceptions in typescript (ins...
# typescript
c
I'm trying to handle exceptions in typescript (inside of an async code). What would be the proper way of handling it? I've not found an exception class or something that I could use to cast such error.
error: Running program '/home/user/development/company/aws-iam-provisioning' failed with an unhandled exception:
Error: invocation of awsssm/getParametergetParameter returned an error: invoking awsssm/getParametergetParameter: 1 error occurred:
* Error describing SSM parameter (eks-name2): ParameterNotFound:
at Object.callback (/home/user/development/company/aws-iam-provisioning/node_modules/@pulumi/pulumi/runtime/invoke.js13933)
at Object.onReceiveStatus (/home/user/development/company/aws-iam-provisioning/node_modules/@grpc/grpc-js/src/client.ts33826)
at Object.onReceiveStatus (/home/user/development/company/aws-iam-provisioning/node_modules/@grpc/grpc-js/src/client-interceptors.ts42634)
at Object.onReceiveStatus (/home/user/development/company/aws-iam-provisioning/node_modules/@grpc/grpc-js/src/client-interceptors.ts38948)
at /home/user/development/company/aws-iam-provisioning/node_modules/@grpc/grpc-js/src/call-stream.ts27624
at processTicksAndRejections (nodeinternal/process/task queues78:11)
The code:
Copy code
try {
    const eksName = await aws.ssm.getParameter({
    name: "eks-name",
    });
} catch(error) {
    // handle error
    console.log(JSON.stringify(error));
}
inside of the catch block, the below will be printed:
Copy code
{
  "promise": {}
}
so it's like I don't have access to the error message, etc could be I'm just lacking some JS/TS skills as well, but I think it should be something like that
s
Copy code
const eksName = await aws.ssm.getParameter({
    name: "eks-name",
}).catch(err => console.log(err) /*handle here*/)
c
@steep-toddler-94095 even with the await there you still have to use the catch function? That's a bit counter intuitive, no? Could be I'm lacking some knowledge here as I'm not a nodejs expert
s
you're correct, you don't need the
await
for the
.catch
to work