Skip to content

Commit

Permalink
Merge branch 'master' into feat-display-error
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Oct 13, 2024
2 parents 8b550b8 + d386c17 commit 0854de3
Show file tree
Hide file tree
Showing 43 changed files with 234 additions and 336 deletions.
20 changes: 0 additions & 20 deletions .autod.conf.js

This file was deleted.

24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

15 changes: 15 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '14, 16, 18, 20, 22'
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release

on:
push:
branches: [ master ]

jobs:
release:
name: Node.js
uses: eggjs/github-actions/.github/workflows/node-release.yml@master
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

24 changes: 24 additions & 0 deletions History.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# Changelog

## [2.3.0](https://github.com/eggjs/egg-onerror/compare/v2.2.0...v2.3.0) (2024-10-13)


### Features

* use [email protected] ([#39](https://github.com/eggjs/egg-onerror/issues/39)) ([fc57345](https://github.com/eggjs/egg-onerror/commit/fc57345661ab6771d74ca5678438bfe7983929a1))

2.2.0 / 2022-12-11
==================

**features**
* [[`a31167c`](http://github.com/eggjs/egg-onerror/commit/a31167ccf6ecc35d51b129299271588b32a51350)] - 👌 IMPROVE: Use currentContext first (#36) (fengmk2 <<[email protected]>>)

2.1.1 / 2022-08-18
==================

**fixes**
* [[`00d2aa2`](http://github.com/eggjs/egg-onerror/commit/00d2aa2a073048dec9b9fc0fd0d868ecc0446830)] - fix: check file exists (#35) (吖猩 <<[email protected]>>)

**others**
* [[`54e12ba`](http://github.com/eggjs/egg-onerror/commit/54e12baa2eab9b47a2acd6ba0e6f6a0e55c92fc0)] - Create codeql-analysis.yml (fengmk2 <<[email protected]>>)
* [[`55d27e6`](http://github.com/eggjs/egg-onerror/commit/55d27e60a9f1094e1a4555e82b47cab4799a57f8)] - chore: update travis (#31) (TZ | 天猪 <<[email protected]>>)

2.1.0 / 2018-06-12
==================
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) Alibaba Group Holding Limited and other contributors.
Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# egg-onerror

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Node.js CI](https://github.com/eggjs/egg-onerror/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-onerror/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-onerror.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-onerror
[travis-image]: https://img.shields.io/travis/eggjs/egg-onerror.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-onerror
[codecov-image]: https://codecov.io/github/eggjs/egg-onerror/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-onerror?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-onerror.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-onerror
[snyk-image]: https://snyk.io/test/npm/egg-onerror/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-onerror
[download-image]: https://img.shields.io/npm/dm/egg-onerror.svg?style=flat-square
Expand All @@ -25,15 +20,15 @@ Default error handling plugin for egg.
## Install

```bash
$ npm i egg-onerror
npm i egg-onerror
```

## Usage

`egg-onerror` is on by default in egg. But you still can configure its properties to fits your scenarios.

- `errorPageUrl: String or Function` - If user request html pages in production environment and unexpected error happened, it will redirect user to `errorPageUrl`.
- `accepts: Function` - detect user's request accpet `json` or `html`.
- `accepts: Function` - detect user's request accept `json` or `html`.
- `all: Function` - customize error handler, if `all` present, negotiation will be ignored.
- `html: Function` - customize html error handler.
- `text: Function` - customize text error handler.
Expand All @@ -42,7 +37,7 @@ $ npm i egg-onerror

```js
// config.default.js
// errorPageUrl support funtion
// errorPageUrl support function
exports.onerror = {
errorPageUrl: (err, ctx) => ctx.errorPageUrl || '/500',
};
Expand All @@ -61,3 +56,9 @@ Please open an issue [here](https://github.com/eggjs/egg/issues).
## License

[MIT](https://github.com/eggjs/egg-onerror/blob/master/LICENSE)

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-onerror)](https://github.com/eggjs/egg-onerror/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
2 changes: 0 additions & 2 deletions agent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

module.exports = agent => {
// should watch error event
agent.on('error', err => {
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const http = require('http');
const fs = require('fs');
const onerror = require('koa-onerror');
Expand All @@ -17,7 +15,9 @@ module.exports = app => {
const viewTemplate = fs.readFileSync(config.templatePath, 'utf8');

app.on('error', (err, ctx) => {
ctx = ctx || app.createAnonymousContext();
if (!ctx) {
ctx = app.currentContext || app.createAnonymousContext();
}
if (config.appErrorFilter && !config.appErrorFilter(err, ctx)) return;

const status = detectStatus(err);
Expand Down
15 changes: 0 additions & 15 deletions appveyor.yml

This file was deleted.

1 change: 0 additions & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const path = require('path');

exports.onerror = {
Expand Down
32 changes: 1 addition & 31 deletions lib/error_view.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// modify from https://github.com/poppinss/youch/blob/develop/src/Youch/index.js

const fs = require('fs');
Expand Down Expand Up @@ -30,8 +28,6 @@ class ErrorView {
* get html error page
*
* @return {String} html page
*
* @memberOf ErrorView
*/
toHTML() {
const stack = this.parseError();
Expand Down Expand Up @@ -60,8 +56,6 @@ class ErrorView {
* @param {Object} locals - data used by template
*
* @return {String} html
*
* @memberOf ErrorView
*/
complieView(tpl, locals) {
return Mustache.render(tpl, locals);
Expand All @@ -72,8 +66,6 @@ class ErrorView {
*
* @param {Frame} frame - current frame
* @return {Boolean} bool
*
* @memberOf ErrorView
*/
isNode(frame) {
if (frame.isNative()) {
Expand All @@ -88,8 +80,6 @@ class ErrorView {
*
* @param {Object} frame - current frame
* @return {Boolean} bool
*
* @memberOf ErrorView
*/
isApp(frame) {
if (this.isNode(frame)) {
Expand All @@ -104,8 +94,6 @@ class ErrorView {
*
* @param {String} key - assert key
* @param {String} value - assert content
*
* @memberOf ErrorView
*/
setAssets(key, value) {
this.assets.set(key, value);
Expand All @@ -115,8 +103,6 @@ class ErrorView {
* get cache file asserts
*
* @param {String} key - assert key
*
* @memberOf ErrorView
*/
getAssets(key) {
this.assets.get(key);
Expand All @@ -127,15 +113,13 @@ class ErrorView {
*
* @param {Object} frame - current frame
* @return {Object} frame source
*
* @memberOf ErrorView
*/
getFrameSource(frame) {
const filename = frame.getFileName();
const lineNumber = frame.getLineNumber();
let contents = this.getAssets(filename);
if (!contents) {
contents = fs.readFileSync(filename, 'utf8');
contents = fs.existsSync(filename) ? fs.readFileSync(filename, 'utf8') : '';
this.setAssets(filename, contents);
}
const lines = contents.split(/\r?\n/);
Expand All @@ -151,8 +135,6 @@ class ErrorView {
* parse error and return frame stack
*
* @return {Array} frame
*
* @memberOf ErrorView
*/
parseError() {
const stack = stackTrace.parse(this.error);
Expand All @@ -169,8 +151,6 @@ class ErrorView {
*
* @param {Object} frame - current frame
* @return {Object} context
*
* @memberOf ErrorView
*/
getContext(frame) {
if (!frame.context) {
Expand All @@ -191,8 +171,6 @@ class ErrorView {
* @param {any} frame - current frame
* @param {any} index - current index
* @return {String} classes
*
* @memberOf ErrorView
*/
getFrameClasses(frame, index) {
const classes = [];
Expand All @@ -212,8 +190,6 @@ class ErrorView {
*
* @param {Object} frame - current frame
* @return {Object} frame result
*
* @memberOf ErrorView
*/
serializeFrame(frame) {
const filename = frame.getFileName();
Expand All @@ -238,8 +214,6 @@ class ErrorView {
* @param {Object} stack - frame stack
* @param {Function} frameFomatter - frame fomatter function
* @return {Object} data
*
* @memberOf ErrorView
*/
serializeData(stack, frameFomatter) {
const code = this.error.code || this.error.type;
Expand All @@ -264,8 +238,6 @@ class ErrorView {
* serialize request object
*
* @return {Object} request object
*
* @memberOf ErrorView
*/
serializeRequest() {

Expand Down Expand Up @@ -302,8 +274,6 @@ class ErrorView {
* serialize app info object
*
* @return {Object} egg app info
*
* @memberOf ErrorView
*/
serializeAppInfo() {
return {
Expand Down
2 changes: 0 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

exports.detectErrorMessage = function(ctx, err) {
// detect json parse error
if (err.status === 400 &&
Expand Down
Loading

0 comments on commit 0854de3

Please sign in to comment.