Skip to content

Commit

Permalink
added warning message area
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ ONeal committed Aug 17, 2012
1 parent b7a9aa9 commit 7a7080c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions http-json/index.js
Expand Up @@ -14,6 +14,24 @@
, resProto = http.ServerResponse.prototype , 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) { resProto.error = function (msg, code, opts) {
var self = this var self = this
; ;
Expand All @@ -23,6 +41,10 @@
opts = {}; opts = {};
} }


if (msg instanceof Error) {
msg = msg.message || msg.toString();
}

opts.message = msg; opts.message = msg;
opts.code = code; opts.code = code;
self._errors.push(opts); self._errors.push(opts);
Expand Down Expand Up @@ -67,6 +89,9 @@
replacer = (opts.debug) ? null : removeStack; replacer = (opts.debug) ? null : removeStack;
response.timestamp = Date.now(); response.timestamp = Date.now();
response.errors = self._errors || []; response.errors = self._errors || [];
if ((self._warns || []).length) {
response.warnings = self._warns || [];
}
response.success = !response.errors.length; response.success = !response.errors.length;
response.result = data; response.result = data;


Expand Down
2 changes: 1 addition & 1 deletion http-json/package.json
Expand Up @@ -2,7 +2,7 @@
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info/)", "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info/)",
"name": "http-json", "name": "http-json",
"description": "An extension of the http prototype supporting steve-style json responses in connect", "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", "homepage": "http://github.com/coolaj86/steve",
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down

0 comments on commit 7a7080c

Please sign in to comment.