小编Cat*_*ish的帖子

hapi.js处理错误的最佳方法

我正在使用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)

javascript rest node.js hapijs

12
推荐指数
2
解决办法
2万
查看次数

用于在PHP中将破折号添加到美国电话号码的功能

在PHP中将破折号添加到电话号码的最佳方法是什么?我有一个格式的数字,xxxxxxxxxx我希望它的格式为xxx-xxx-xxxx.这仅适用于10位美国电话号码.

php

11
推荐指数
2
解决办法
3万
查看次数

Rails:是否有更新或update_attributes在失败时抛出异常?

是否存在等效model.updatemodel.update_attributes失败的异常?

似乎没有update!update_attributes!

ruby-on-rails ruby-on-rails-3

11
推荐指数
2
解决办法
6376
查看次数

Eclipse Markdown插件 - 双击.md文件时如何打开Markdown HTML Preview?

我刚安装了Eclipse的Markdown插件.我希望如此,如果我双击.md文件,它将打开markdown HTML预览视图,或者至少能够在Markdown HTML预览中右键单击并查看.

反正有没有这样做?

eclipse markdown eclipse-plugin

10
推荐指数
1
解决办法
1万
查看次数

如何断言两个列表<String>相等,忽略顺序

我正在使用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)"

java assertj

9
推荐指数
3
解决办法
6562
查看次数

jQuery $ .post和json_encode返回一个带引号的字符串

我正在使用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)

ajax jquery json

8
推荐指数
1
解决办法
1万
查看次数

refinerycms图像无法加载 - 蜻蜓错误

我正在开发一个在本地工作良好的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)

ruby-on-rails refinerycms ruby-on-rails-3 dragonfly-gem

8
推荐指数
2
解决办法
4126
查看次数

Activeadmin渲染'new'给出在尝试覆盖create controller方法时找不到没有id的User

我正在尝试在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)

ruby ruby-on-rails activeadmin ruby-on-rails-4

8
推荐指数
3
解决办法
1642
查看次数

节点脚本永远不会结束

我有下面的节点脚本基本上复制一些文件的内容并将它们插入到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)

javascript mongoose mongodb node.js

8
推荐指数
2
解决办法
3863
查看次数

每次使用AES时,Crypto-js都会返回不同的值

我正在尝试使用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 encryption node.js cryptojs

8
推荐指数
1
解决办法
2035
查看次数