koatty_exception
Advanced tools
Comparing version 1.3.2-6 to 1.3.2
@@ -5,2 +5,12 @@ # Changelog | ||
### [1.3.2](https://github.com/koatty/koatty_exception/compare/v1.3.2-6...v1.3.2) (2024-02-02) | ||
### Bug Fixes | ||
* constructor ([59a92d0](https://github.com/koatty/koatty_exception/commit/59a92d0c8a429554e97859bdd5cadf6f72d346a4)) | ||
* log ([d1a3808](https://github.com/koatty/koatty_exception/commit/d1a38080744f3d0d352a683f4f8ad69175ed7f62)) | ||
* span log ([453f51e](https://github.com/koatty/koatty_exception/commit/453f51e343e06bf165c5b5beb3e3bb2cc8155894)) | ||
* 去除status默认值 ([6ecc75c](https://github.com/koatty/koatty_exception/commit/6ecc75c907cf65053c0f1ce93071a3785968d144)) | ||
### [1.3.2-6](https://github.com/koatty/koatty_exception/compare/v1.3.2-5...v1.3.2-6) (2024-01-24) | ||
@@ -7,0 +17,0 @@ |
/*! | ||
* @Author: richen | ||
* @Date: 2024-01-24 15:57:28 | ||
* @Date: 2024-02-02 09:35:09 | ||
* @License: BSD (3-Clause) | ||
@@ -33,5 +33,5 @@ * @Copyright (c) - <richenlin(at)gmail.com> | ||
constructor(message: string, code?: number, status?: number, stack?: string, span?: Span); | ||
setCode(code: number): this; | ||
setStatus(status: number): this; | ||
setMessage(message: string): this; | ||
setCode(code: number): this; | ||
setStack(stack: string): this; | ||
@@ -442,7 +442,3 @@ setSpan(span: Span): this; | ||
*/ | ||
export declare const isException: <T extends { | ||
message: string; | ||
code?: number; | ||
status?: unknown; | ||
}>(err: Exception | T) => boolean; | ||
export declare const isException: (err: any) => boolean; | ||
@@ -449,0 +445,0 @@ /** |
/*! | ||
* @Author: richen | ||
* @Date: 2024-01-24 15:57:17 | ||
* @Date: 2024-02-02 09:34:58 | ||
* @License: BSD (3-Clause) | ||
@@ -10,6 +10,6 @@ * @Copyright (c) - <richenlin(at)gmail.com> | ||
var koatty_logger = require('koatty_logger'); | ||
var Helper = require('koatty_lib'); | ||
var opentracing = require('opentracing'); | ||
var Helper = require('koatty_lib'); | ||
var koatty_container = require('koatty_container'); | ||
var koatty_logger = require('koatty_logger'); | ||
var grpcJs = require('@grpc/grpc-js'); | ||
@@ -585,7 +585,14 @@ | ||
this.type = "Exception"; | ||
this.status = status; | ||
this.code = code; | ||
this.stack = stack; | ||
this.span = span; | ||
this.setCode(code); | ||
this.setStatus(status); | ||
this.setMessage(message); | ||
this.setSpan(span); | ||
this.setStack(stack); | ||
} | ||
setCode(code) { | ||
if (Helper.Helper.isNumber(code)) { | ||
this.code = code; | ||
} | ||
return this; | ||
} | ||
setStatus(status) { | ||
@@ -603,8 +610,2 @@ if (status >= 100 && status < 600) { | ||
} | ||
setCode(code) { | ||
if (Helper.Helper.isNumber(code)) { | ||
this.code = code; | ||
} | ||
return this; | ||
} | ||
setStack(stack) { | ||
@@ -629,17 +630,8 @@ if (stack) { | ||
const now = Date.now(); | ||
const path = ctx.originalPath || '/'; | ||
const duration = (now - ctx.startTime) || 0; | ||
koatty_logger.DefaultLogger.Error(`{"startTime":"${ctx.startTime}","duration":"${duration}","requestId":"${ctx.requestId}","endTime":"${now}","path":"${path}","message":"${this.message}","stack":"${this.stack}"`); | ||
const message = { | ||
"startTime": ctx.startTime, | ||
"duration": duration, | ||
"requestId": ctx.requestId, | ||
"endTime": now, | ||
"path": path, | ||
"message": this.message, | ||
}; | ||
// LOG | ||
let message = `{"startTime":"${ctx.startTime}","duration":"${(now - ctx.startTime) || 0}","requestId":"${ctx.requestId}","endTime":"${now}","path":"${ctx.originalPath || '/'}","message":"${this.message}"`; | ||
if (this.stack) { | ||
message['stack'] = this.stack; | ||
message = `${message},stack:"${this.stack}"`; | ||
} | ||
message = `${message}}`; | ||
koatty_logger.DefaultLogger.Error(message); | ||
// span | ||
@@ -651,3 +643,3 @@ if (this.span) { | ||
this.span.setTag(opentracing.Tags.HTTP_URL, ctx.url); | ||
this.span.log(message); | ||
this.span.log({ "error": message }); | ||
} | ||
@@ -663,3 +655,3 @@ return; | ||
try { | ||
ctx.status = this.status || ctx.status || 500; | ||
ctx.status = this.status || ctx.status; | ||
// LOG | ||
@@ -720,3 +712,3 @@ this.log(ctx); | ||
* @Date: 2022-02-10 17:40:55 | ||
* @LastEditTime: 2023-01-13 10:02:29 | ||
* @LastEditTime: 2024-02-01 10:48:46 | ||
*/ | ||
@@ -749,3 +741,3 @@ const PREVENT_NEXT_PROCESS = 'PREVENT_NEXT_PROCESS'; | ||
const isException = (err) => err instanceof Exception || | ||
!!(err && Object.hasOwnProperty.call(err, "handler") && Object.hasOwnProperty.call(err, "code")); | ||
!!(err && err.type === "Exception"); | ||
@@ -752,0 +744,0 @@ exports.Exception = Exception; |
{ | ||
"name": "koatty_exception", | ||
"version": "1.3.2-6", | ||
"version": "1.3.2", | ||
"description": "Exception handler for koatty.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
{ | ||
"name": "koatty_exception", | ||
"version": "1.3.2-6", | ||
"version": "1.3.2", | ||
"description": "Exception handler for koatty.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
98816
1965