@aptly-as/sdk-nodejs 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  import { AptlyErrorCode } from '@aptly-as/types';
2
+ declare const ERROR_NAME = "AptlyResponseError";
2
3
  export interface AptlyResponseErrorJson extends Omit<AptlyResponseErrorData, 'errors'> {
4
+ name: typeof ERROR_NAME;
3
5
  errors?: AptlyResponseErrorJsonSimple[];
4
6
  }
5
7
  export interface AptlyResponseErrorData {
@@ -28,7 +30,7 @@ export declare enum AptlyLogLevel {
28
30
  export declare class AptlyResponseError extends Error {
29
31
  readonly status: number;
30
32
  private props;
31
- name: string;
33
+ readonly name = "AptlyResponseError";
32
34
  private _id;
33
35
  static ofError(error: Error): AptlyResponseError;
34
36
  constructor(status: number, message: string, props?: AptlyResponseErrorProps);
@@ -44,3 +46,4 @@ export declare class AptlyResponseError extends Error {
44
46
  toString(): string;
45
47
  res(_request: any, _response: any): void;
46
48
  }
49
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { AptlyErrorCode } from '@aptly-as/types';
2
+ const ERROR_NAME = 'AptlyResponseError';
2
3
  export var AptlyLogLevel;
3
4
  (function (AptlyLogLevel) {
4
5
  AptlyLogLevel["Fatal"] = "fatal";
@@ -11,9 +12,9 @@ export var AptlyLogLevel;
11
12
  export class AptlyResponseError extends Error {
12
13
  static ofError(error) {
13
14
  const responseError = Object.setPrototypeOf(error, AptlyResponseError.prototype);
14
- responseError.status = 500;
15
15
  return Object.assign(responseError, {
16
- name: 'ResponseError',
16
+ status: 500,
17
+ name: ERROR_NAME,
17
18
  props: {
18
19
  code: AptlyErrorCode.Default,
19
20
  level: AptlyLogLevel.Error,
@@ -27,7 +28,7 @@ export class AptlyResponseError extends Error {
27
28
  super(message);
28
29
  this.status = status;
29
30
  this.props = props;
30
- this.name = 'ResponseError';
31
+ this.name = ERROR_NAME;
31
32
  this._id = '';
32
33
  this.status = status;
33
34
  this._id = props.id || '';
@@ -65,6 +66,7 @@ export class AptlyResponseError extends Error {
65
66
  };
66
67
  }
67
68
  return {
69
+ name: this.name,
68
70
  id: this._id,
69
71
  status: this.status,
70
72
  code: this.code,
@@ -86,4 +88,3 @@ export class AptlyResponseError extends Error {
86
88
  throw new Error('AptlyResponseError res function has not been implemented.');
87
89
  }
88
90
  }
89
- //# sourceMappingURL=ResponseError.js.map
package/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './error/ResponseError.js';
2
2
  export * from './logging/logging.js';
3
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export const pinoPrettierMessageFormat = '{sessionID} {req.id} {req.url} \x1b[32m{msg}\x1b[0m :{res.statusCode} - {responseTime}ms ';
2
- //# sourceMappingURL=logging.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptly-as/sdk-nodejs",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Aptly SDK library for node.js applications",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import { AptlyErrorCode } from '@aptly-as/types';
2
- import { describe, expect, test } from 'vitest';
3
- import { createGeneralTestError } from '../test/test.utils.js';
4
- import { AptlyResponseError, AptlyLogLevel } from './ResponseError.js';
5
- describe('AptlyResponseError', () => {
6
- test('should init', () => {
7
- const error = new AptlyResponseError(500, 'message', {
8
- errors: [],
9
- error: new Error(),
10
- level: AptlyLogLevel.Debug,
11
- id: 'id',
12
- detail: 'Some detail here',
13
- link: 'link for helping to debug',
14
- });
15
- expect(error).instanceof(AptlyResponseError);
16
- });
17
- test('should create json for body', () => {
18
- const responseError = AptlyResponseError.ofError(new Error('JSON'));
19
- const json = responseError.toJSON();
20
- expect(json).to.have.keys('id', 'code', 'detail', 'errors', 'status', 'title', 'message', 'link');
21
- });
22
- test('should create simple json for body', () => {
23
- const responseError = AptlyResponseError.ofError(new Error('JSON'));
24
- const json = responseError.toJSON(true);
25
- expect(json).to.have.keys('code', 'detail', 'title', 'message', 'link');
26
- });
27
- test('should be created from normal error', () => {
28
- const error = createGeneralTestError();
29
- const responseError = AptlyResponseError.ofError(error).setId('id');
30
- expect(error).instanceof(AptlyResponseError);
31
- expect(responseError).instanceof(AptlyResponseError);
32
- expect(responseError.id).to.equal('id');
33
- expect(responseError.level).to.equal(AptlyLogLevel.Error);
34
- expect(responseError.code).to.equal(AptlyErrorCode.Default);
35
- expect(responseError.link).to.equal('');
36
- expect(responseError.detail).to.equal('');
37
- expect(Array.isArray(responseError.errors)).toBeTruthy();
38
- expect(responseError.log).toBeTypeOf('function');
39
- expect(responseError.toString).toBeTypeOf('function');
40
- expect(responseError.toJSON).toBeTypeOf('function');
41
- expect(responseError.stack).to.contain('\\test\\test.utils.ts');
42
- expect(responseError.toJSON()).to.deep.equal({
43
- id: 'id',
44
- status: 500,
45
- code: AptlyErrorCode.Default,
46
- title: 'Error from another file',
47
- message: 'Error from another file',
48
- detail: '',
49
- link: '',
50
- errors: [],
51
- });
52
- });
53
- });
54
- //# sourceMappingURL=ResponseError.test.js.map