mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
errors working with babel 6, export v3 shared modules in main common module
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
var pathToCommon;
|
||||
'use strict';
|
||||
|
||||
let pathToCommon;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
pathToCommon = './transpiled-babel/index';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import extendableBuiltin from './libs/extendableBuiltin';
|
||||
|
||||
// Base class for custom application errors
|
||||
// It extends Error and capture the stack trace
|
||||
export class CustomError extends Error {
|
||||
export class CustomError extends extendableBuiltin(Error) {
|
||||
constructor () {
|
||||
super();
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
|
||||
11
common/script/api-v3/libs/extendableBuiltin.js
Normal file
11
common/script/api-v3/libs/extendableBuiltin.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// Babel 6 doesn't support extending native class (Error, Array, ...)
|
||||
// This function makes it possible to extend native classes with the same results as Babel 5
|
||||
module.exports = function extendableBuiltin (klass) {
|
||||
function ExtendableBuiltin () {
|
||||
klass.apply(this, arguments);
|
||||
}
|
||||
ExtendableBuiltin.prototype = Object.create(klass.prototype);
|
||||
Object.setPrototypeOf(ExtendableBuiltin, klass);
|
||||
|
||||
return ExtendableBuiltin;
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../website/src/libs/api-v3/errors';
|
||||
} from './errors';
|
||||
import i18n from '../i18n';
|
||||
|
||||
const MAX_TASK_VALUE = 21.27;
|
||||
|
||||
@@ -18,8 +18,17 @@ var $w, preenHistory, sortOrder,
|
||||
import content from './content/index';
|
||||
import i18n from './i18n';
|
||||
|
||||
import * as errors from './api-v3/errors';
|
||||
import scoreTask from './api-v3/scoreTask';
|
||||
|
||||
let api = module.exports = {};
|
||||
|
||||
// Temporary location of API v3 files (soon to be removed)
|
||||
api.v3 = {
|
||||
scoreTask,
|
||||
errors,
|
||||
};
|
||||
|
||||
api.i18n = i18n;
|
||||
api.shouldDo = shouldDo;
|
||||
|
||||
|
||||
@@ -10,13 +10,14 @@ import {
|
||||
NotAuthorized,
|
||||
BadRequest,
|
||||
} from '../../libs/api-v3/errors';
|
||||
import shared from '../../../../common';
|
||||
import common from '../../../../common';
|
||||
import Q from 'q';
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
import scoreTask from '../../../../common/script/api-v3/scoreTask';
|
||||
import { preenHistory } from '../../libs/api-v3/preening';
|
||||
|
||||
const scoreTask = common.v3.scoreTask;
|
||||
|
||||
let api = {};
|
||||
|
||||
// challenge must be passed only when a challenge task is being created
|
||||
@@ -334,8 +335,8 @@ api.updateTask = {
|
||||
|
||||
function _generateWebhookTaskData (task, direction, delta, stats, user) {
|
||||
let extendedStats = _.extend(stats, {
|
||||
toNextLevel: shared.tnl(user.stats.lvl),
|
||||
maxHealth: shared.maxHealth,
|
||||
toNextLevel: common.tnl(user.stats.lvl),
|
||||
maxHealth: common.maxHealth,
|
||||
maxMP: user._statsComputed.maxMP, // TODO refactor as method not getter
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { CustomError } from '../../../../common/script/api-v3/errors';
|
||||
import common from '../../../../common/script';
|
||||
|
||||
export const CustomError = common.v3.errors.CustomError;
|
||||
|
||||
/**
|
||||
* @apiDefine NotAuthorized
|
||||
@@ -11,7 +13,7 @@ import { CustomError } from '../../../../common/script/api-v3/errors';
|
||||
* "message": "Not authorized."
|
||||
* }
|
||||
*/
|
||||
export { NotAuthorized } from '../../../../common/script/api-v3/errors';
|
||||
export const NotAuthorized = common.v3.errors.NotAuthorized;
|
||||
|
||||
/**
|
||||
* @apiDefine BadRequest
|
||||
@@ -24,7 +26,7 @@ export { NotAuthorized } from '../../../../common/script/api-v3/errors';
|
||||
* "message": "Bad request."
|
||||
* }
|
||||
*/
|
||||
export { BadRequest } from '../../../../common/script/api-v3/errors';
|
||||
export const BadRequest = common.v3.errors.BadRequest;
|
||||
|
||||
/**
|
||||
* @apiDefine NotFound
|
||||
@@ -37,7 +39,7 @@ export { BadRequest } from '../../../../common/script/api-v3/errors';
|
||||
* "message": "Not found."
|
||||
* }
|
||||
*/
|
||||
export { NotFound } from '../../../../common/script/api-v3/errors';
|
||||
export const NotFound = common.v3.errors.NotFound;
|
||||
|
||||
/**
|
||||
* @apiDefine InternalServerError
|
||||
|
||||
@@ -9,9 +9,10 @@ import Task from '../../models/task';
|
||||
import Q from 'q';
|
||||
import Group from '../../models/group';
|
||||
import User from '../../models/user';
|
||||
import scoreTask from '../../../../common/script/api-v3/scoreTask';
|
||||
import { preenUserHistory } from '../../libs/api-v3/preening';
|
||||
|
||||
const scoreTask = common.v3.scoreTask;
|
||||
|
||||
let clearBuffs = {
|
||||
str: 0,
|
||||
int: 0,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// The error handler middleware that handles all errors
|
||||
// and respond to the client
|
||||
import logger from '../../libs/api-v3/logger';
|
||||
import { CustomError } from '../../../../common/script/api-v3/errors';
|
||||
import {
|
||||
CustomError,
|
||||
BadRequest,
|
||||
InternalServerError,
|
||||
} from '../../libs/api-v3/errors';
|
||||
|
||||
Reference in New Issue
Block a user