binhend 1.1.8 → 1.1.10
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.
- package/package.json +1 -1
- package/src/api.js +11 -11
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -86,21 +86,21 @@ function trycatch(callback, onerror) {
|
|
|
86
86
|
return await callback(request, response, next);
|
|
87
87
|
}
|
|
88
88
|
catch (error) {
|
|
89
|
-
if (onerror instanceof Function) onerror(error);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
89
|
+
if (onerror instanceof Function) return onerror(error);
|
|
90
|
+
var message = error instanceof HttpError && error.message || 'Internal Server Error';
|
|
91
|
+
response.status(error.code || 500).json({ error: message });
|
|
92
|
+
if (onerror === true) console.error('\x1b[31m', error);
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
97
|
+
class HttpError extends Error {
|
|
98
|
+
constructor(code, message) {
|
|
99
|
+
super(message);
|
|
100
|
+
this.name = 'HttpError';
|
|
101
|
+
this.code = code;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
104
|
|
|
105
105
|
module.exports = {
|
|
106
106
|
APIs, Router, HttpError
|