我正在使用hapi.js创建我的第一个node.js REST Web服务.我很好奇处理错误的最佳方法,让我们从我的dao层说出来.throw在我的dao层中做他们然后只是try/catch阻止他们处理它们并在我的控制器中发回错误,或者有一个更好的方式,酷孩子正在处理这个?
路线/ task.js
var taskController = require('../controllers/task');
//var taskValidate = require('../validate/task');
module.exports = function() {
return [
{
method: 'POST',
path: '/tasks/{id}',
config : {
handler: taskController.createTask//,
//validate : taskValidate.blah
}
}
]
}();
Run Code Online (Sandbox Code Playgroud)
控制器/ task.js
var taskDao = require('../dao/task');
module.exports = function() {
return {
/**
* Creates a task
*
* @param req
* @param reply
*/
createTask: function createTask(req, reply) {
taskDao.createTask(req.payload, function (err, data) {
// TODO: Properly handle errors …Run Code Online (Sandbox Code Playgroud) 在PHP中将破折号添加到电话号码的最佳方法是什么?我有一个格式的数字,xxxxxxxxxx我希望它的格式为xxx-xxx-xxxx.这仅适用于10位美国电话号码.
是否存在等效model.update或model.update_attributes失败的异常?
似乎没有update!或update_attributes!
我刚安装了Eclipse的Markdown插件.我希望如此,如果我双击.md文件,它将打开markdown HTML预览视图,或者至少能够在Markdown HTML预览中右键单击并查看.
反正有没有这样做?
我正在使用AssertJ,我试图断言两个List<String>包含相同的字符串,忽略顺序.
List<String> expected = Arrays.asList("Something-6144-77.pdf", "d-6144-77.pdf", "something-6144-78.pdf", "Something-6144-8068.pdf");
List<String> actual = new ArrayList<String>();
assertThat(actual.size()).isEqualTo(expected.size());
// This line gives the error: "The method containsExactlyInAnyOrder(String...) in the type ListAssert<String> is not applicable for the arguments (List<String>)"
assertThat(actual).containsExactlyInAnyOrder(expected);
Run Code Online (Sandbox Code Playgroud)
如何修复下面尝试使用时出现的编译错误containsExactlyInAnyOrder()?
"ListAssert类型中的方法containsExactlyInAnyOrder(String ...)不适用于参数(List)"
我正在使用jQuery的$ .post调用,它返回一个带引号的字符串.引号由json_encode行添加.如何阻止添加引号?我在$ .post电话中遗漏了什么?
$.post("getSale.php", function(data) {
console.log('data = '+data); // is showing the data with double quotes
}, 'json');
Run Code Online (Sandbox Code Playgroud) 我正在开发一个在本地工作良好的refinerycms rails应用程序,现在我已将它移动到我的VPS,我遇到的问题是我通过refinerycms上传的图像没有加载,我一直在阅读我需要升级我的imagemagick版本.我从6.2.8升级到6.7.8.现在图像都加载到某些页面上,但不在管理端加载.
是什么导致了这个问题?这是错误的堆栈跟踪.
Dragonfly::Shell::CommandFailed (Command failed (convert '/var/www/vhosts/tomstestsite.us/PersonalTrainingKT/public/system/refinery/images/2012/06/03/16_36_48_339_pamLemke_after.jpg' '-resize' '225x255>' '/tmp/dragonfly20120705-7812-1xb3pce') with exit status 127):
dragonfly (0.9.12) lib/dragonfly/shell.rb:29:in `raise_shell_command_failed'
dragonfly (0.9.12) lib/dragonfly/shell.rb:23:in `run'
dragonfly (0.9.12) lib/dragonfly/image_magick/utils.rb:17:in `convert'
dragonfly (0.9.12) lib/dragonfly/image_magick/processor.rb:103:in `convert'
dragonfly (0.9.12) lib/dragonfly/image_magick/processor.rb:27:in `resize'
dragonfly (0.9.12) lib/dragonfly/image_magick/processor.rb:87:in `thumb'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:39:in `call'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:39:in `block (2 levels) in call_last'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:38:in `catch'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:38:in `block in call_last'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:37:in `each'
dragonfly (0.9.12) lib/dragonfly/function_manager.rb:37:in `call_last'
dragonfly (0.9.12) lib/dragonfly/processor.rb:5:in `process'
dragonfly (0.9.12) lib/dragonfly/job.rb:79:in `apply'
dragonfly (0.9.12) lib/dragonfly/job.rb:253:in …Run Code Online (Sandbox Code Playgroud) 我正在尝试在activeadmin中创建一个页面,用户可以进入该页面并创建新的用户帐户.
我正在使用下面的代码覆盖我的用户模型的默认创建方法.
我Couldn't find User without an ID尝试渲染new页面时收到错误.
尝试重新渲染new动作时,为什么会出现此错误?
ActiveAdmin.register User do
permit_params do
permitted = [:email, :encrypted_password]
permitted << :admin if current_user.is_admin?
permitted
end
# We're overriding the new and edit controller methods to properly create users with devise. Otherwise the passwords don't get encrypted
controller do
def create
user = User.new
user.name = params[:user][:name]
user.email = params[:user][:email]
user.admin = params[:user][:admin]
user.password = params[:user][:encrypted_password]
user.password_confirmation = params[:user][:encrypted_password]
if user.save
redirect_to admin_user_path(user)
else
flash.now[:error] …Run Code Online (Sandbox Code Playgroud) 我有下面的节点脚本基本上复制一些文件的内容并将它们插入到mongo.
脚本似乎永远不会结束,即使所有数据都成功插入,我总是要按Ctrl + C来杀死它.
我应该在node.js中使用什么来结束脚本?
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/testdb');
var dir = './seeds';
var db = mongoose.connection;
// Show connection error if there is one
db.on('error', console.error.bind(console, 'Database Connection Error:'));
// If we successfully connected to mongo
db.once('open', function callback() {
var fs = require('fs'); // Used to get all the files in a directory
// Read all the files in the folder
fs.readdir(dir, function(err, list) {
// Log the error if something went wrong
if(err) {
console.log('Error: '+err); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用crypto-js和使用AES类型的加密来加密某些东西.
我遇到的问题是每次加密时我的加密值都不同.
通过这个简单的例子,我运行相同的加密5次不同,我得到5个不同的结果.Wtf在这里发生了什么?
task.js
var AES = require('crypto-js/aes');
var key = "abc123";
var secret = "encryptThisWord";
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
console.log(AES.encrypt(secret, key).toString());
Run Code Online (Sandbox Code Playgroud)

javascript ×3
node.js ×3
activeadmin ×1
ajax ×1
assertj ×1
cryptojs ×1
eclipse ×1
encryption ×1
hapijs ×1
java ×1
jquery ×1
json ×1
markdown ×1
mongodb ×1
mongoose ×1
php ×1
refinerycms ×1
rest ×1
ruby ×1