1

Не понимаю почему не получается получить значение singUp

router.get('/', async (request, response) => {

  let model = new Model();

  response.send(model.account.singUp);

}); 

function Model(){
}

Model.prototype.account = {
  singUp: 1,
  activate: 1
}

Не понимаю на что ругается, проблема точно не в методе send

express deprecated res.send(status): Use res.sendStatus(status) instead routers/others/test.js:12:12
***/node_modules/mysql/lib/protocol/Parser.js:80
        throw err; // Rethrow non-MySQL errors
        ^

RangeError: Invalid status code: 1
    at ServerResponse.writeHead (_http_server.js:194:11)
    at ServerResponse.writeHead (***/node_modules/on-headers/index.js:55:19)
    at ServerResponse._implicitHeader (_http_server.js:185:8)
    at ServerResponse.end (_http_outgoing.js:754:10)
    at writeend (***/node_modules/express-session/index.js:261:22)
    at ontouch (***/node_modules/express-session/index.js:348:11)
    at Query._callback (***/node_modules/express-mysql-session/index.js:254:17)
    at Query.Sequence.end (***/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Query._handleFinalResultPacket (***/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
    at Query.OkPacket (***/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (***/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (***/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (***/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (***/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:607:20)

Скажите возможно ли вообще обратиться так к элементам объекта?

2
  • 2
    The body parameter can be a Buffer object, a String, an object, or an Array - ты же пытаешься послать число - и падаешь, потому что парсер думает ты хочешь статус отправить. Попробуй заменить 1 на '1'
    – Grundy
    24 апр 2018 в 17:36
  • Круто, теперь все ясно. Спасибо за помощь!
    – FAT_BOY
    25 апр 2018 в 1:34

1 ответ 1

1

Как указано в описании:

The body parameter can be a Buffer object, a String, an object, or an Array

Параметр body может быть объектом Buffer, строкой, объектом или массивом

В данном случае передается число и идет попытка вызвать устаревшую перегрузку send отправляющую статус.

Для решения нужно отправлять либо сам объект account

response.send(model.account);

Либо хранить в полях объекта не числа, а строки:

singUp: '1'

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.