UNPKG

dl

Version:

DreamLab Libs

50 lines (38 loc) 1.47 kB
var Class = require("core").Class; var JsonRpcResponse = require("core").jsonrpc.JsonRpcResponse; var JsonRpcBatchResponse = require("core").jsonrpc.JsonRpcBatchResponse; var Response = require("core").http.Response; var Types = require("core").common.Types; var OpalResponse = function(){ this.Extends = Response; /*this.initialize = function(data){ this.setStatusCode(data.statusCode); this.setHeaders(data.headers); this.setHttpVersion(data.httpVersion); this.setBody(data.body); };*/ this.initialize = function(params){ this.parent(params); }; this.setBody = this._setBody = function(body){ var isValid = false; if(Types.isInstanceOf(body, JsonRpcResponse) || Types.isInstanceOf(body, Response)){ isValid = true; }else if(Types.isInstanceOf(body, JsonRpcBatchResponse)){ isValid = true; }else if(Types.isString(body)){ try{ body = new JsonRpcResponse(body); isValid = true; }catch(e){} } if(!isValid){ throw OpalResponse.Exceptions.WRONG_BODY; } this._body = body; }; }; OpalResponse = new Class(new OpalResponse()); OpalResponse.Exceptions = {}; OpalResponse.Exceptions.WRONG_BODY = 'Body has to be either a proper json-rpc string or object'; exports.OpalResponse = OpalResponse;