私は自分の例外を作成しようとしています。 したがって、nodejsサーバーが実行されている環境に基づいてエラーをフォーマットできます。エラーがスローされると、これは未定義です。カスタム例外。これは定義されていません
(function() {
'use strict';
var states = require('../states');
var env = states.config.env;
var _ = require('underscore');
/**
* This is a error that is going to be thrown on server errors.
* The application format the message for the specific environment
* @param error The error
*/
var unrecoverableError = function (error) {
this.name = 'unrecoverableError';
this.message = _.isEqual(env, 'production') ? 'There was a server error. Please contact server admin' : error.toString();
this.code = 500;
};
unrecoverableError.prototype = Object.create(Error.prototype);
unrecoverableError.prototype.constructor = unrecoverableError;
module.exports = unrecoverableError;
}());
私もORMとして続ける。
organisation.findOne({
where: {
name: organisationName
}
})
.then(function (organisation) {
if (_.isEmpty(organisation)) {
throw new modelNotFoundException();
} else {
resolve(organisation);
}
})
.catch(function (error) {
if (error instanceof modelNotFoundException) {
reject(error);
} else {
throw new unrecoverableError(error);
}
})
.catch(function (error) {
reject(error);
});
次に、私のコンソールにエラーが表示されます。
:
私は私が間違って何をしたかを把握することはできません[TypeError例外は、未定義のプロパティ「name」を設定できません]。それはブラウザで動作しています。 ここで動作するバイブルの例です。事前にhttps://jsfiddle.net/y3gk0hos/
おかげで
私は新しい権利でそれを呼んでいますか?それともあなたが間違っているか分かっています。 "新しいunrecoverableError(エラー)をスローする;" –
解決策は動作しますが、これが正しい解決策であるかどうかわかりません。 –