Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new field to store who is sending the error #6

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 54 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hckrnews/error",
"description": "Extended Errors",
"version": "0.2.0",
"version": "0.2.1",
"author": {
"name": "Pieter Wigboldus",
"url": "https://hckr.news/"
Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/app-error.unit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/** global: describe */
import { AppError } from '../index';
import { AppError } from '../index.js';

describe('App Error test', () => {
it('It should create a app error', () => {
const error = new AppError({
value: 'test',
type: String,
message: 'Example text',
me: AppError,
});

expect(error instanceof AppError).toEqual(true);
Expand All @@ -18,13 +19,15 @@ describe('App Error test', () => {
expect(error.type).toEqual(String);
expect(error.date.constructor).toEqual(Date);
expect(error.stack.includes('AppError: Example text')).toEqual(true);
expect(error.me).toEqual(AppError);
});

it('It should handle invalid error values', () => {
const error = new AppError({
value: 'test',
type: 'string',
message: 'Example text',
me: AppError,
});

expect(error instanceof AppError).toEqual(true);
Expand All @@ -41,5 +44,6 @@ describe('App Error test', () => {
expect(error.type).toEqual(Error);
expect(error.date.constructor).toEqual(Date);
expect(error.stack.includes('AppError: Invalid error')).toEqual(true);
expect(error.me).toEqual(AppError);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/not-found-error.unit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** global: describe */
import { NotFoundError } from '../index';
import { NotFoundError } from '../index.js';

describe('Not Found Error test', () => {
it('It should create a not found error', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/not-implemented-error.unit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** global: describe */
import { NotImplementedError } from '../index';
import { NotImplementedError } from '../index.js';

describe('Not Implemented Error test', () => {
it('It should create a not implemented error', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/server-error.unit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** global: describe */
import { ServerError } from '../index';
import { ServerError } from '../index.js';

describe('Server Error test', () => {
it('It should create a server error', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/validation-error.unit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** global: describe */
import { ValidationError } from '../index';
import { ValidationError } from '../index.js';

describe('Validation Error test', () => {
it('It should create a validation error', () => {
Expand Down
8 changes: 5 additions & 3 deletions src/app-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const validator = new Validator(errorSchema);

export default (error = Error) =>
class AppError extends error {
constructor({ value = null, type = null, message }) {
constructor({ value = null, type = null, message, me = null }) {
super(message);

if (Error.captureStackTrace) {
Error.captureStackTrace(this, AppError);
}

this.setValues({ value, type });
this.setValues({ value, type, me });
}

get name() {
Expand All @@ -27,9 +27,10 @@ export default (error = Error) =>
return this.hasErrors ? 500 : this.errorStatus;
}

setValues({ value, type }) {
setValues({ value, type, me }) {
this.value = value;
this.type = type;
this.me = me;
this.date = new Date();

if (!this.validate()) {
Expand All @@ -51,6 +52,7 @@ export default (error = Error) =>
status: this.errorStatus,
type: this.type,
date: this.date,
me: this.me,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/schemas/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export default {
status: Number,
'type?': Function,
date: Date,
};;
};