by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 02 06:16
    @ljharb banned @frank-dspeed
  • Apr 27 2018 01:23
    @MylesBorins banned @fjeddy
  • Feb 24 2016 08:26
    @rvagg banned @jonathanenbe
sgda021992
@sgda021992
yeah
Jordan Harband
@ljharb
seems like you may want to pick a better library that supports something like json schema
sgda021992
@sgda021992
yeah but if you could help me with regex .... that will be apriciated
Jordan Harband
@ljharb
do you support leading zeroes?
ie is 05 less than 6?
what about negative numbers, or zero
or 00000
Brian Crowder
@crowder
Been staring at this document for a while -- it does not much discuss how the build/linkage is meant to work: https://nodejs.org/api/embedding.html <--- anyone have any hints for me?
Also: is there a better room for me to go to? :)
Jordan Harband
@ljharb
this is the best room on gitter; the best actual room is on freenode IRC, #node.js for regular questions and #node-dev for C++ questions
Brian Crowder
@crowder
@ljharb Thanks!
Brian Crowder
@crowder
@ljharb Don't suppose you've any hints, in the meantime?
Jordan Harband
@ljharb
only to prefer pure js modules :-)
Liviu Lupei
@liviulupei
Hi everyone, I'm working in the team who created Endtest.
I've dealt with all the possible corner cases for testing NodeJS apps, I've join this channel to help others.
https://endtest.io
TamashiKaizenカイゼン
@TamashiKaizen
Jordan Harband
@ljharb
class extends Error { get name() { return ‘custom’; } }?
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb Hi, it seems like the name cannot be retrieved using custom class method.
TypeError: err.getName is not a function`
class AppError extends Error {
    constructor(message, statusCode){
        super(message);

        this.statusCode = statusCode;
        this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';        
        this.isOperational = true;        

        Error.captureStackTrace(this, this.constructor);
    }

    setName(name) {
        this.name = name;
    }
    getName(){
        return this.name;
    }
}

module.exports = AppError;
Jordan Harband
@ljharb
not .getName. get name - a property getter
get name() {} means that new AppError().name will call that function
you could also do AppError.prototype.name = ‘AppError’, which would be better.
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb sorry i don't quite understand the get name() {} function.
Can you send an example code?
@ljharb If i use AppError.prototype.name = ‘AppError’, will it affect the prototype.name of other natural errors?
@ljharb It seems like the errorHandler can only retrieve the name of the natural errors, but not for custom error name appended and manually thrown.
Jordan Harband
@ljharb
i already sent the example code. verbatim.
and no, it won't affect other erros
AppError.prototype is only for AppErrors.
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb should i use throw instead? The error.name value does appear in centralErrorHandler but i'm not sure if using throw err; is correct.
if (!errors.isEmpty()) {
        let err = new AppError(`Invalid login credentials.`, 422);
        err.name = 'ExpressValidatorError';            

       throw err;
      }
Jordan Harband
@ljharb
you should, but that's not related to the name
you should probably set the name in the constructor tho
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb thank you :)
@ljharb what is the difference of return next(err); and throw err; ?
Jordan Harband
@ljharb
oh, you didn’t say it was in an express middleware
yes definitely return next(err)
the difference is that throw doesn’t work async unless it’s in a promise.
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb ohh i see, thank you
TamashiKaizenカイゼン
@TamashiKaizen
@ljharb i changed the AppError class to this, but don't know why the error.name passed to the errorHandler still console logs as undefined
class AppError extends Error {
    constructor(name, statusCode, message){
        super(message);

        this.name = name;
        this.statusCode = statusCode;
        this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error';        
        this.isOperational = true;                   

        Error.captureStackTrace(this, this.constructor);
    }              
}

module.exports = AppError;
if (!errors.isEmpty()) {
        console.log(errors.array());
        let err = new AppError('ExpressValidatorError', 422, 'Invalid login credentials.');                     
        return next(err);
      }
errorHandler.js
module.exports = (err, req, res, next) => {        
    err.statusCode = err.statusCode || 500;
    err.status = err.status || 'error';    


        let error = {...err};             

        console.log(error.name);

        if(error.name === 'ExpressValidatorError') error = handleExpressValidatorError(error);

        if(error.name === 'InternalOAuthError') error = handleInternalOAuthError(error);


}
Mile Mijatović
@mijatovicmile
Hello
I have Node.js Code assignment challenge
Since getting the conversion rate is a long and CPU consuming task (for the sake of this
assignment of course) and the company only allows you to buy up to 2 small cloud instances,
you let the company know that it will be best to defer the user requests and email the results
back to them once it is ready (in a reasonable amount of time).
Assumptions:
- Create a dummy async function that will send the email, no need to actually send it
Please advice me , what's the best solution to achieve that ?
with Node.js
@ljharb
Ibrahim Hussein
@DevIbrahimHussein
 // save to database
    newCategory.save()
    .then(category => {

        // add category to family
        Family.findOneAndUpdate(category.family,function(err,family){
            if(err) return res.send(err);
            family.categories.push(category.id)
            family.save(function(err,fam){
                if(err) return res.send(err);
                res.send(fam);
            })
        })

        res.send(category);
    }).catch(err => {
        res.status(500).send({
            message: err.message || "Some error occured"
        })
    })

problem

not added to categories in family schema

Schema

const FamilySchema = new Schema({
    title: {
        type: String,
        require: true
    },
    categories: [
        {
            type: Schema.Types.ObjectId,
            ref: Category
        }
    ]
});
poonam20nikam
@poonam20nikam
HI
Sidharth-Bansal
@Sidharth-Bansal
How to handle redirects fired from node to display specific screens in the react native?
vivekweb2013
@vivekweb2013
https://github.com/vivekweb2013/toastmaker - small & useful npm module for showing toast