Skip to content
Browse files

added warning message area

  • Loading branch information...
1 parent b7a9aa9 commit 7a7080cfb7403824d0a333c212d993b903458990 @coolaj86 committed Aug 17, 2012
Showing with 26 additions and 1 deletion.
  1. +25 −0 http-json/index.js
  2. +1 −1 http-json/package.json
View
25 http-json/index.js
@@ -14,6 +14,24 @@
, resProto = http.ServerResponse.prototype
;
+ resProto.warn = function (msg, code, opts) {
+ var self = this
+ ;
+
+ self._warns = self._warns || [];
+ if ('object' !== typeof opts) {
+ opts = {};
+ }
+
+ if (msg instanceof Error) {
+ msg = msg.message || msg.toString();
+ }
+
+ opts.message = msg;
+ opts.code = code;
+ self._warns.push(opts);
+ };
+
resProto.error = function (msg, code, opts) {
var self = this
;
@@ -23,6 +41,10 @@
opts = {};
}
+ if (msg instanceof Error) {
+ msg = msg.message || msg.toString();
+ }
+
opts.message = msg;
opts.code = code;
self._errors.push(opts);
@@ -67,6 +89,9 @@
replacer = (opts.debug) ? null : removeStack;
response.timestamp = Date.now();
response.errors = self._errors || [];
+ if ((self._warns || []).length) {
+ response.warnings = self._warns || [];
+ }
response.success = !response.errors.length;
response.result = data;
View
2 http-json/package.json
@@ -2,7 +2,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info/)",
"name": "http-json",
"description": "An extension of the http prototype supporting steve-style json responses in connect",
- "version": "1.0.2",
+ "version": "1.1.0",
"homepage": "http://github.com/coolaj86/steve",
"repository": {
"type": "git",

0 comments on commit 7a7080c

Please sign in to comment.
Something went wrong with that request. Please try again.