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
Jordan Harband
@ljharb
why would you use regex for that
sgda021992
@sgda021992
i want to put check in json
Jordan Harband
@ljharb
json doesn’t support regexes
sgda021992
@sgda021992
if you build form using json
Jordan Harband
@ljharb
maybe step back and explain what you’re trying to do, instead of asking about the way you think you should do it
sgda021992
@sgda021992
it will work
Jordan Harband
@ljharb
if you write code that treats some of your json strings as regexes, then sure
but that’s not a great idea
sgda021992
@sgda021992
i am using a library that accept json and generate form on UI
Jordan Harband
@ljharb
ok
and the only validation mechanism they support is regex? O.o
sgda021992
@sgda021992
so if we want to put any kind of validation that comes in json only
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);
      }