问:
Do you understand the problem on this POST request with lambda function?
I use netlify lambda functions for CRUD operations on my project but i have an error on the POST operation

I use angular front, netlify functions and faunaDB

my lambda:

```<code>/* code from functions/todos-create.js */
import faunadb from 'faunadb' /* Import faunaDB sdk */

/* configure faunaDB Client with our secret */
const q = faunadb.query
const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
})

/* export our lambda function as named "handler" export */
exports.handler = (event, context, callback) => {
  /* parse the string body into a useable JS object */
  console.log('<<<<<<<<<' + "      " + event.body + "       " + '>>>>>>>>>')
  const eventBody = JSON.stringify(event.body)
  const data = JSON.parse(eventBody)
  console.log("Function `todo-create` invoked", data)
  const todoItem = {
    data: data
  }
  /* construct the fauna query */
  return client.query(q.Create(q.Ref("classes/todos"), todoItem))
  .then((response) => {
    console.log("success", response)
    /* Success! return the response with statusCode 200 */
    return callback(null, {
      statusCode: 200,
      body: JSON.stringify(response)
    })
  }).catch((error) => {
    console.log("error", error)
    /* Error! return the error with statusCode 400 */
    return callback(null, {
      statusCode: 400,
      body: JSON.stringify(error)
    })
  })
}
</code>```

a piece of my component:

```<code>public myTodo = { title: 'What I had for breakfast ..',
                    completed: true };

onSubmit() {
    this.missionService.createTodo(this.myTodo).then((response) => {
      console.log('console log of missionService.createTodo ---->');
      console.log(this.myTodo);
      console.log('API response', response);
    }).catch((error) => {
      console.log('API error', error);
    });
  }

</code>```

my service:

```<code>  createTodo(data) {
    console.log('console log of createTodo ---->');
    console.log(data);
    return fetch('/.netlify/functions/todos-create', {
      body: JSON.stringify(data),
      method: 'POST'
    }).then(response => {
      return response.json();
    });
  }
</code>```

And finnaly the execution error....

```<code>Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked {"title":"What I had for breakfast ..","completed":true}
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '******************'
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559144535321508 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Wed, 29 May 2019 15:42:15 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '129',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '0',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559144535321508',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559144535024,
[BACK] [LAMBDA]      endTime: 1559144535439 } }
[BACK] [LAMBDA] Response with status 400 in 417 ms.
[BACK] [LAMBDA] (node:10193) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:10193) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
</code>```

GET request is functional, i tried it.
Do you have any idea of the problem please ?

答:
remove the stringify change nothing, I added console logs in lambda function for more details:

```<code>/* code from functions/todos-create.js */
import faunadb from 'faunadb' /* Import faunaDB sdk */

/* configure faunaDB Client with our secret */
const q = faunadb.query
const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
})

/* export our lambda function as named "handler" export */
exports.handler = (event, context, callback) => {
  /* parse the string body into a useable JS object */
  console.log('<<<<<<<<<' + "      " + event.body + "       " + '>>>>>>>>>')
  const eventBody = JSON.stringify(event.body)
  console.log('<<<<<<<<<' + "      " + eventBody + "       " + '>>>>>>>>>')
  const data = JSON.parse(eventBody)
  console.log('<<<<<<<<<' + "      " + data + "       " + '>>>>>>>>>')
  console.log("Function `todo-create` invoked", data)
  const todoItem = {
    data: data
  }
  // {"title":"What I had for breakfast ..","completed":true}
  console.log('<<<<<<<<<' + "      " + todoItem + "       " + '>>>>>>>>>')
  /* construct the fauna query */
  return client.query(q.Create(q.Ref("classes/todos"), todoItem))
  .then((response) => {
    console.log("success", response)
    /* Success! return the response with statusCode 200 */
    return callback(null, {
      statusCode: 200,
      body: JSON.stringify(response)
    })
  }).catch((error) => {
    console.log("error", error)
    /* Error! return the error with statusCode 400 */
    return callback(null, {
      statusCode: 400,
      body: JSON.stringify(error)
    })
  })
}
</code>```

error without stringify in fetch body:

```<code>[BACK] [LAMBDA] Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      "[object Object]"       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked [object Object]
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '*************************',
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559289243066157 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Fri, 31 May 2019 07:54:03 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '82',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '3',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559289243066157',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559289242318,
[BACK] [LAMBDA]      endTime: 1559289243199 } }
[BACK] [LAMBDA] Response with status 400 in 883 ms.
[BACK] [LAMBDA] (node:5201) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:5201) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 7)
</code>```

error with:

```<code>[BACK] [LAMBDA] Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      "{\"title\":\"What I had for breakfast ..\",\"completed\":true}"       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked {"title":"What I had for breakfast ..","completed":true}
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] (node:11199) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '****************************',
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559294662744534 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Fri, 31 May 2019 09:24:22 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '129',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '0',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559294662744534',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559294662390,
[BACK] [LAMBDA]      endTime: 1559294663102 } }
[BACK] [LAMBDA] Response with status 400 in 762 ms.
[BACK] [LAMBDA] (node:11199) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:11199) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[BACK] [LAMBDA] (node:11199) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
</code>```

it works with directly (in lambda function):

```<code>const todoItem = {
    data: {"title":"What I had for breakfast ..","completed":true}
  }
</code>```

Body:
I use netlify lambda functions for CRUD operations on my project but i have an error on the POST operation

I use angular front, netlify functions and faunaDB

my lambda:

/* code from functions/todos-create.js */
import faunadb from 'faunadb' /* Import faunaDB sdk */

/* configure faunaDB Client with our secret */
const q = faunadb.query
const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
})

/* export our lambda function as named "handler" export */
exports.handler = (event, context, callback) => {
  /* parse the string body into a useable JS object */
  console.log('<<<<<<<<<' + "      " + event.body + "       " + '>>>>>>>>>')
  const eventBody = JSON.stringify(event.body)
  const data = JSON.parse(eventBody)
  console.log("Function `todo-create` invoked", data)
  const todoItem = {
    data: data
  }
  /* construct the fauna query */
  return client.query(q.Create(q.Ref("classes/todos"), todoItem))
  .then((response) => {
    console.log("success", response)
    /* Success! return the response with statusCode 200 */
    return callback(null, {
      statusCode: 200,
      body: JSON.stringify(response)
    })
  }).catch((error) => {
    console.log("error", error)
    /* Error! return the error with statusCode 400 */
    return callback(null, {
      statusCode: 400,
      body: JSON.stringify(error)
    })
  })
}

a piece of my component:

public myTodo = { title: 'What I had for breakfast ..',
                    completed: true };

onSubmit() {
    this.missionService.createTodo(this.myTodo).then((response) => {
      console.log('console log of missionService.createTodo ---->');
      console.log(this.myTodo);
      console.log('API response', response);
    }).catch((error) => {
      console.log('API error', error);
    });
  }

my service:

  createTodo(data) {
    console.log('console log of createTodo ---->');
    console.log(data);
    return fetch('/.netlify/functions/todos-create', {
      body: JSON.stringify(data),
      method: 'POST'
    }).then(response => {
      return response.json();
    });
  }

And finnaly the execution error....

Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked {"title":"What I had for breakfast ..","completed":true}
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '******************'
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559144535321508 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Wed, 29 May 2019 15:42:15 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '129',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '0',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559144535321508',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559144535024,
[BACK] [LAMBDA]      endTime: 1559144535439 } }
[BACK] [LAMBDA] Response with status 400 in 417 ms.
[BACK] [LAMBDA] (node:10193) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:10193) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)

GET request is functional, i tried it.
Do you have any idea of the problem please ?

Body:
remove the stringify change nothing, I added console logs in lambda function for more details:

/* code from functions/todos-create.js */
import faunadb from 'faunadb' /* Import faunaDB sdk */

/* configure faunaDB Client with our secret */
const q = faunadb.query
const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
})

/* export our lambda function as named "handler" export */
exports.handler = (event, context, callback) => {
  /* parse the string body into a useable JS object */
  console.log('<<<<<<<<<' + "      " + event.body + "       " + '>>>>>>>>>')
  const eventBody = JSON.stringify(event.body)
  console.log('<<<<<<<<<' + "      " + eventBody + "       " + '>>>>>>>>>')
  const data = JSON.parse(eventBody)
  console.log('<<<<<<<<<' + "      " + data + "       " + '>>>>>>>>>')
  console.log("Function `todo-create` invoked", data)
  const todoItem = {
    data: data
  }
  // {"title":"What I had for breakfast ..","completed":true}
  console.log('<<<<<<<<<' + "      " + todoItem + "       " + '>>>>>>>>>')
  /* construct the fauna query */
  return client.query(q.Create(q.Ref("classes/todos"), todoItem))
  .then((response) => {
    console.log("success", response)
    /* Success! return the response with statusCode 200 */
    return callback(null, {
      statusCode: 200,
      body: JSON.stringify(response)
    })
  }).catch((error) => {
    console.log("error", error)
    /* Error! return the error with statusCode 400 */
    return callback(null, {
      statusCode: 400,
      body: JSON.stringify(error)
    })
  })
}

error without stringify in fetch body:

[BACK] [LAMBDA] Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      "[object Object]"       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked [object Object]
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '*************************',
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559289243066157 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Fri, 31 May 2019 07:54:03 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '82',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '3',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559289243066157',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559289242318,
[BACK] [LAMBDA]      endTime: 1559289243199 } }
[BACK] [LAMBDA] Response with status 400 in 883 ms.
[BACK] [LAMBDA] (node:5201) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:5201) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 7)

error with:

[BACK] [LAMBDA] Request from ::ffff:127.0.0.1: POST /todos-create
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      "{\"title\":\"What I had for breakfast ..\",\"completed\":true}"       >>>>>>>>>
[BACK] [LAMBDA] <<<<<<<<<      {"title":"What I had for breakfast ..","completed":true}       >>>>>>>>>
[BACK] [LAMBDA] Function `todo-create` invoked {"title":"What I had for breakfast ..","completed":true}
[BACK] [LAMBDA] <<<<<<<<<      [object Object]       >>>>>>>>>
[BACK] [LAMBDA] (node:11199) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[BACK] [LAMBDA] error { [BadRequest: validation failed]
[BACK] [LAMBDA]   name: 'BadRequest',
[BACK] [LAMBDA]   message: 'validation failed',
[BACK] [LAMBDA]   requestResult:
[BACK] [LAMBDA]    RequestResult {
[BACK] [LAMBDA]      client:
[BACK] [LAMBDA]       Client {
[BACK] [LAMBDA]         _baseUrl: 'https://db.fauna.com:443',
[BACK] [LAMBDA]         _timeout: 60000,
[BACK] [LAMBDA]         _secret: '****************************',
[BACK] [LAMBDA]         _observer: null,
[BACK] [LAMBDA]         _lastSeen: 1559294662744534 },
[BACK] [LAMBDA]      method: 'POST',
[BACK] [LAMBDA]      path: '',
[BACK] [LAMBDA]      query: null,
[BACK] [LAMBDA]      requestRaw: undefined,
[BACK] [LAMBDA]      requestContent: Expr { raw: [Object] },
[BACK] [LAMBDA]      responseRaw:
[BACK] [LAMBDA]       '{"errors":[{"position":[],"code":"validation failed","description":"Instance data is not valid.","failures":[{"field":["data"],"code":"invalid type","description":"Invalid type String, expected type Map."}]}]}',
[BACK] [LAMBDA]      responseContent: { errors: [Array] },
[BACK] [LAMBDA]      statusCode: 400,
[BACK] [LAMBDA]      responseHeaders:
[BACK] [LAMBDA]       { 'content-type': 'application/json;charset=utf-8',
[BACK] [LAMBDA]         date: 'Fri, 31 May 2019 09:24:22 GMT',
[BACK] [LAMBDA]         'x-bus-bytes-in': '0',
[BACK] [LAMBDA]         'x-bus-bytes-out': '0',
[BACK] [LAMBDA]         'x-bus-messages-in': '0',
[BACK] [LAMBDA]         'x-bus-messages-out': '0',
[BACK] [LAMBDA]         'x-faunadb-build': '2.6.4.rc4-3fa8865',
[BACK] [LAMBDA]         'x-faunadb-host': 'ec2-35-173-239-41.compute-1.amazonaws.com',
[BACK] [LAMBDA]         'x-points-network-out': '0.0',
[BACK] [LAMBDA]         'x-points-storage-read': '0.0',
[BACK] [LAMBDA]         'x-points-storage-write': '0.0',
[BACK] [LAMBDA]         'x-points-total': '0.0',
[BACK] [LAMBDA]         'x-query-bytes-in': '129',
[BACK] [LAMBDA]         'x-query-bytes-out': '209',
[BACK] [LAMBDA]         'x-query-time': '0',
[BACK] [LAMBDA]         'x-read-ops': '0',
[BACK] [LAMBDA]         'x-storage-bytes-read': '0',
[BACK] [LAMBDA]         'x-storage-bytes-write': '0',
[BACK] [LAMBDA]         'x-storage-ops-delete': '0',
[BACK] [LAMBDA]         'x-storage-ops-read': '0',
[BACK] [LAMBDA]         'x-storage-ops-write': '0',
[BACK] [LAMBDA]         'x-txn-delay': '0',
[BACK] [LAMBDA]         'x-txn-retries': '0',
[BACK] [LAMBDA]         'x-txn-time': '1559294662744534',
[BACK] [LAMBDA]         'x-write-ops': '0',
[BACK] [LAMBDA]         'content-length': '209',
[BACK] [LAMBDA]         connection: 'Close' },
[BACK] [LAMBDA]      startTime: 1559294662390,
[BACK] [LAMBDA]      endTime: 1559294663102 } }
[BACK] [LAMBDA] Response with status 400 in 762 ms.
[BACK] [LAMBDA] (node:11199) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
[BACK] [LAMBDA]     at callback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:35:42)
[BACK] [LAMBDA]     at /home/mathieu/Bureau/acrabadabra/Acrabadabra/node_modules/netlify-lambda/lib/serve.js:67:7
[BACK] [LAMBDA]     at tryCatch (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1803:12)
[BACK] [LAMBDA]     at invokeCallback (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1818:13)
[BACK] [LAMBDA]     at publish (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1792:7)
[BACK] [LAMBDA]     at flush (/home/mathieu/Bureau/acrabadabra/Acrabadabra/functions/todos-create.js:1522:5)
[BACK] [LAMBDA]     at process._tickCallback (internal/process/next_tick.js:61:11)
[BACK] [LAMBDA] (node:11199) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
[BACK] [LAMBDA] (node:11199) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

it works with directly (in lambda function):

const todoItem = {
    data: {"title":"What I had for breakfast ..","completed":true}
  }


来源: stackexchange

问:
Azure AKS add node with different Linux OS
When using a Kuberenetes service on Azure the nodes are by default built with an Ubuntu image.

I have a use case of wanting to add more nodes but on the az CLI the os-type is only Linux (ubuntu) or Windows.

Is there a way of adding a Node to an existing Kubernetes cluster on Azure that is of different Linux types like CentOS?

答: AKS only supports ubuntu at this time, so this is not yet possible</p>

ContentLicense: CC BY-SA 4.0


问:
Dotnet upgrade - 2.0 to 3.5 - performance
We have a number of winforms apps that are written in dotnet 2.0.  Are there any performance upgrades that we would expect when taking transistion to 3.5 runtime?  Any particular benefits we will get, besides the language features?</p>

答: The 3.0 and 3.5 language features run on the core .NET 2.0 runtime.  They are essentially library upgrades.  You should notice no difference in performance.</p>

OwnerDisplayName: mek

ContentLicense: CC BY-SA 3.0

OwnerDisplayName: Jim

ContentLicense: CC BY-SA 2.5


问:
Problem adding values stored as variables to a java list
I am going to create a list that I want to add elements to.  I have obtained the elements from clients via them completing 3 dialogue boxes indicating their preferences for a new car, and now I want to add these entries to the list.

I have declared my instance variables and here is the constructor for my list:

```<code> public Car(String aMaker, String aModel, int aYearBuilt);
    {
        super();
        this.maker = aMaker;
        this.model = aModel;
        this.year = aYearBuilt;
    }
</code>```

I have successfully put the return from my first client's dialogue boxes into 3 variables, created thus:

```<code> String inputMaker;
 String inputModel;
 int inputYear;
</code>```

(I remembered to use Integer.parseInt to convert the dialogue input string to an int).

Now I want to put the values in a list:

```<code>List<Car> newCarDetails = new ArrayList<Car>();
</code>```

This is where I start to go wrong:

```<code> newCarDetails.add(new Car(inputMaker, inputModel, inputYear));
    return newCarDetails;
</code>```

Only I have clearly underestimated the task, because it doesn't work.  I just get a hashCode back.  Any help greatly appreciated.

答:
You haven't actually said what you're trying to do with the returned value, or how it's really behaving, only this:

Only I have clearly underestimated the task, because it doesn't work. I just get a hashCode back. Any help greatly appreciated.

Hmm. My psychic debugging skills suggest that you're calling toString on either the ArrayList<Car> or the Car itself, and that's returning something which doesn't look terribly useful.

Options:

Use the individual values within the Car when you're formatting (e.g. by calling the properties)

Override toString in the Car class with your chosen format

If neither of those are useful, please edit your question to give more information about what you're doing with the list...

Body:
I am going to create a list that I want to add elements to.  I have obtained the elements from clients via them completing 3 dialogue boxes indicating their preferences for a new car, and now I want to add these entries to the list.

I have declared my instance variables and here is the constructor for my list:

 public Car(String aMaker, String aModel, int aYearBuilt);
    {
        super();
        this.maker = aMaker;
        this.model = aModel;
        this.year = aYearBuilt;
    }

I have successfully put the return from my first client's dialogue boxes into 3 variables, created thus:

 String inputMaker;
 String inputModel;
 int inputYear;

(I remembered to use Integer.parseInt to convert the dialogue input string to an int).

Now I want to put the values in a list:

List<Car> newCarDetails = new ArrayList<Car>();

This is where I start to go wrong:

 newCarDetails.add(new Car(inputMaker, inputModel, inputYear));
    return newCarDetails;

Only I have clearly underestimated the task, because it doesn't work.  I just get a hashCode back.  Any help greatly appreciated.


问:
Use ChaiHttp with beforeEach or before method
I have an NodeJS Express application which I want to unit test which uses cookies. So I want to use a beforeEach or before to create the Cookie.

Code which works without any problem (but without the before method):

```<code>import * as chai from 'chai';
import { expect } from 'chai'
import chaiHttp = require('chai-http');

import { app } from '../../server';
describe('Relaties', () => {
    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            let agent = chai.request.agent(app)
            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    // The `agent` now has the sessionid cookie saved, and will send it
                    // back to the server in the next request:
                    return agent.get('/api/ehrm-klantnr/relatie')
                        .set('meta','1')
                        .then(function (res) {
                            expect(res).to.have.status(200);
                            expect(res.body.data[0].vestiging).to.equal('Slib Hoofdkantoor');
                            done();
                        });
                });
        });
    });
});

</code>```

What does not run is this:

```<code>import * as chai from 'chai';
import { expect } from 'chai'
import chaiHttp = require('chai-http');

import { app } from '../../server';
 describe('Relaties', () => {
    let agent = chai.request.agent(app);

    describe('First this one', function () {
        beforeEach(function () {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                });
        });
    });

    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            return agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    expect(res.body.data[0].vestiging).to.equal('Slib Hoofdkantoor');
                    done();
                });
        });
    });
});

</code>```

It is completely ignoring my before or beforeEach (both methods don't work).
Maybe chai-http does not have  before or beforeEach support ?
What am I doing wrong ?

After restructuring.

```<code>describe('Relaties', () => {
    const agent = chai.request.agent(app);

        beforeEach(function (done) {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    done();
                });
        });

    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            return agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    expect(res).to.be.an('object');
                    expect(res.body.data).to.be.an('array');
                    expect(res.body.data[0]).to.be.an('object');
                    expect(res.body.data[0].id).to.equal(1);
                    done();
                });
        });
    });
});
</code>```

I still get errors about the promise.

答:
If this is usefull for someone, this is the final solution:</p>

```<code>
 describe('Relaties', () => {
    const agent = chai.request.agent(app);

        beforeEach(function (done) {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    done();
                });
        });

     describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    done();
                });
        });
    });
});

</code>```

Body:
I have an NodeJS Express application which I want to unit test which uses cookies. So I want to use a beforeEach or before to create the Cookie.

Code which works without any problem (but without the before method):

import * as chai from 'chai';
import { expect } from 'chai'
import chaiHttp = require('chai-http');

import { app } from '../../server';
describe('Relaties', () => {
    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            let agent = chai.request.agent(app)
            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    // The `agent` now has the sessionid cookie saved, and will send it
                    // back to the server in the next request:
                    return agent.get('/api/ehrm-klantnr/relatie')
                        .set('meta','1')
                        .then(function (res) {
                            expect(res).to.have.status(200);
                            expect(res.body.data[0].vestiging).to.equal('Slib Hoofdkantoor');
                            done();
                        });
                });
        });
    });
});

What does not run is this:

import * as chai from 'chai';
import { expect } from 'chai'
import chaiHttp = require('chai-http');

import { app } from '../../server';
 describe('Relaties', () => {
    let agent = chai.request.agent(app);

    describe('First this one', function () {
        beforeEach(function () {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                });
        });
    });

    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            return agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    expect(res.body.data[0].vestiging).to.equal('Slib Hoofdkantoor');
                    done();
                });
        });
    });
});

It is completely ignoring my before or beforeEach (both methods don't work).
Maybe chai-http does not have  before or beforeEach support ?
What am I doing wrong ?

After restructuring.

describe('Relaties', () => {
    const agent = chai.request.agent(app);

        beforeEach(function (done) {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    done();
                });
        });

    describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            return agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    expect(res).to.be.an('object');
                    expect(res.body.data).to.be.an('array');
                    expect(res.body.data[0]).to.be.an('object');
                    expect(res.body.data[0].id).to.equal(1);
                    done();
                });
        });
    });
});

I still get errors about the promise.

Body:
If this is usefull for someone, this is the final solution:

 describe('Relaties', () => {
    const agent = chai.request.agent(app);

        beforeEach(function (done) {
            console.log('outer describe - beforeEach');

            agent
                .put('/api/ehrm-klantnr/medewerker/login')
                .send({ email: 'admin@sfgtest.com', wachtwoord: '<secret>' })
                .then(function (res) {
                    expect(res).to.have.cookie('SESSIONID');
                    done();
                });
        });

     describe('Ophalen alle relaties met: GET /api/ehrm-klantnr/relatie', () => {
        it('should get alle relaties', (done) => {

            agent.get('/api/ehrm-klantnr/relatie')
                .set('meta', '1')
                .then(function (res) {
                    expect(res).to.have.status(200);
                    done();
                });
        });
    });
});


问:
^ and $ expressed in fundamental operations in regular expressions
I've read a book where it states that all fundamental operations in regular expressions are concatatenation, or(|), closure(*) and parenthesis to override default precedence. Every other operation is just a shortcut for one or more fundamental operations.

For example, (AB)+ shortcut is expanded to (AB)(AB)* and (AB)? to (ε | AB) where ε is empty string. First of all, I looked up ASCII table and I am not sure which charcode is designated to empty string. Is it ASCII 0?

I'd like to figure out how to express the shortcuts ^ and $ as in ^AB or AB$ expression in the fundamental operations, but I am not sure how to do this. Can you help me out how this is expressed in fundamentals?

答:
Regular expressions, the way they are defined in mathematics, are actually string generators, not search patterns. They are used as a convenient notation for a certain class of sets of strings. (Those sets can contain an infinite number of strings, so enumerating all elements is not practical.)

In a programming context, regexes are usually used as flexible search patterns. In mathematical terms we're saying, "find a substring of the target string S that is an element of the set generated by regex R". This substring search is not part of the regex proper; it's like there's a loop around the actual regex engine that tries to match every possible substring against the regex (and stops when it finds a match).

In fundamental regex terms, it's like there's an implicit .* added before and after your pattern. When you look at it this way, ^ and $ simply prevent .* from being added at the beginning/end of the regex.

As an aside, regexes (as commonly used in programming) are not actually "regular" in the mathematical sense; i.e. there are many constructs that cannot be translated to the fundamental operations listed above. These include backreferences (\1, \2, ...), word boundaries (\b, \<, \>), look-ahead/look-behind assertions ((?= ), (?! ), (?<= ), (?<! )), and others.

As for ε: It has no character code because the empty string is a string, not a character. Specifically, a string is a sequence of characters, and the empty string contains no characters.


问:
v-model and scoped slots not working?
I have a component:

```<code><slot name="test" :name="name">
    <input type="text" v-model="name">
</slot>
</code>```

The input is bound to name in data.

When I use the slot in the parent:

```<code><div slot="test" slot-scope="props">
    <input type="text" v-model="props.name">
</div>
</code>```

Data does not update on the child. It's not linked - why?

答:
to use v-model in scoped slots, the value of v-model must be one level deeper:

```<code>Vue.component('render-props', {
  data: () => ({message: 'hello', obj: {msg: 'obj_msg'}}),
  template: `<div>
    <slot name="a" :message="message">
      default: {{message}}
      <input v-model="message"/>
    </slot>
    <slot name="b" :obj="obj">
      default: {{obj.msg}}
      <input v-model="obj.msg"/>
    </slot>
  </div>`
});
new Vue({
  el: "#root",
  template: `<div>
    <render-props>
      <template v-slot:a="props">
        actual: {{props.message}}
        <input v-model="props.message"/>
      </template>
      <template v-slot:b="props">
        actual: {{props.obj.msg}}
        <input v-model="props.obj.msg"/>
      </template>
    </render-props>
    <cus_2 />
  </div>`
});
</code>```

Title: v-model and scoped slots not working?

Body:
I have a component:

<slot name="test" :name="name">
    <input type="text" v-model="name">
</slot>

The input is bound to name in data.

When I use the slot in the parent:

    <input type="text" v-model="props.name">

Data does not update on the child. It's not linked - why?

Body:
to use v-model in scoped slots, the value of v-model must be one level deeper:

Vue.component('render-props', {
  data: () => ({message: 'hello', obj: {msg: 'obj_msg'}}),
  template: `<div>
    <slot name="a" :message="message">
      default: {{message}}
      <input v-model="message"/>
    </slot>
    <slot name="b" :obj="obj">
      default: {{obj.msg}}
      <input v-model="obj.msg"/>
    </slot>
  </div>`
});
new Vue({
  el: "#root",
  template: `<div>
    <render-props>
      <template v-slot:a="props">
        actual: {{props.message}}
        <input v-model="props.message"/>
      </template>
      <template v-slot:b="props">
        actual: {{props.obj.msg}}
        <input v-model="props.obj.msg"/>
      </template>
    </render-props>
    <cus_2 />
  </div>`
});