Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

[WIP] Fix fail method #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions template/node10-express-armhf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class FunctionEvent {

class FunctionContext {
constructor(cb) {
this.value = 200;
this.cb = cb;
this.statusCode;
this.headerValues = {};
}

status(value) {
if(!value) {
return this.value;
status(statusCode) {
if(!statusCode) {
return this.statusCode;
}

this.value = value;
this.statusCode = statusCode;
return this;
}

Expand All @@ -46,25 +46,23 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
let err;
this.cb(err, value);
succeed(message) {
this.cb(200, message);
}

fail(value) {
let message;
this.cb(value, message);
fail(message) {
this.cb(500, message);
}
}

var middleware = (req, res) => {
let cb = (err, functionResult) => {
if (err) {
console.error(err);
return res.status(500).send(err);
let cb = (statusCode, functionResult) => {
// If fnContext.status() has not been called, use the default status code of 200 (succeed), or 500 (fail)
if (!fnContext.status()) {
fnContext.status(statusCode);
}

if(isArray(functionResult) || isObject(functionResult)) {
Expand Down Expand Up @@ -96,3 +94,5 @@ let isArray = (a) => {
let isObject = (a) => {
return (!!a) && (a.constructor === Object);
};

module.exports = app;
32 changes: 16 additions & 16 deletions template/node10-express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class FunctionEvent {

class FunctionContext {
constructor(cb) {
this.value = 200;
this.cb = cb;
this.statusCode;
this.headerValues = {};
}

status(value) {
if(!value) {
return this.value;
status(statusCode) {
if(!statusCode) {
return this.statusCode;
}

this.value = value;
this.statusCode = statusCode;
return this;
}

Expand All @@ -46,25 +46,23 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
let err;
this.cb(err, value);
succeed(message) {
this.cb(200, message);
}

fail(value) {
let message;
this.cb(value, message);
fail(message) {
this.cb(500, message);
}
}

var middleware = (req, res) => {
let cb = (err, functionResult) => {
if (err) {
console.error(err);
return res.status(500).send(err);
let cb = (statusCode, functionResult) => {
// If fnContext.status() has not been called, use the default status code of 200 (succeed), or 500 (fail)
if (!fnContext.status()) {
fnContext.status(statusCode);
}

if(isArray(functionResult) || isObject(functionResult)) {
Expand Down Expand Up @@ -96,3 +94,5 @@ let isArray = (a) => {
let isObject = (a) => {
return (!!a) && (a.constructor === Object);
};

module.exports = app;