mapAndLogError
The mapAndLogError() function calls mapError on an Error object and sends the output to standard error. This includes the error name, message, and a call stack.
If --enable-stack-traces is specified during the build, the call stack will be mapped using source maps.
If --enable-stack-traces is specified and --exclude-sources is not specified during the build, then this will also include a code dump of neighboring lines of user code.
Syntax
mapAndLogError(error)
Parameters
error_: Error _ or string- The error to retrieve information about. If a
stringis provided, then it is first converted to anError.
- The error to retrieve information about. If a
Return value
undefined.
Examples
In this example, build the application using the --enable-stack-traces flag.
addEventListener('fetch', e => e.respondWith(handler(e)));
async function handler(event) {
try {
throw new TypeError('foo');
} catch (err) {
mapAndLogError(mapError(err));
}
return new Response('ok');
}
The following is output to the error log.
TypeError: foo
at handler (src/index.ts:4:11)
1 | addEventListener('fetch', e => e.respondWith(handler(e)));
2 | async function handler(event) {
3 | try {
> 4 | throw new TypeError('foo');
^
5 | } catch (err) {
6 | mapAndLogError(mapError(err));
7 | }
at src/index.ts:1:45