@syncmarket/error-serializer
v1.0.0
Published
A library for serializing JavaScript errors with support for custom error data.
Downloads
3
Maintainers
Readme
error-serializer
Una biblioteca para serializar errores en JavaScript.
Instalación
# npm
npm install @syncmarket/error-serializer
#yarn
yarn add @syncmarket/error-serializer
#pnpm
pnpm install @syncmarket/error-serializer
Uso
Importación
import { ErrorSerializer } from '@syncmarket/error-serializer';
Uso
import { ErrorSerializer } from '@syncmarket/error-serializer';
class FakeError extends Error { }
class ErrorWithData extends Error {
constructor (message, cause) {
super(message)
this.cause = cause
this.item = 'test item'
this.otherItem = 'other item'
}
}
const serializer = new ErrorSerializer(
new ErrorWithData('message error', new FakeError())
)
console.log(serializer.extractMetadataByError())
/*
{
ErrorWithData: { otherItem: 'other item', item: 'test item' },
FakeError: {}
}
*/
console.log(serializer.jsonFullStackTrace())
/*
{
name: 'ErrorWithData',
error: 'message error',
stack: [
'Error: message error',
'at Object.<anonymous>'
],
metadata: { item: 'test item' },
cause: {
name: 'FakeError',
error: '',
stack: [
'Error',
'at Object.<anonymous> ,
],
metadata: {},
cause: undefined
}
}
*/