Welcome to the Linux Foundation Forum!

id === 'c060' ch 5 labs-1 model.js

edited January 2021 in LFW212 Class Forum

Hi in chapter 5 labs-1 model.js in the function named read

there is an if clause that looks like this

  1. if (id === 'c060') {
  2. setImmediate(() => cb(Error('unknown')))
  3. }

The entire function looks like this

  1. function read (id, cb) {
  2. if (id === 'c060') {
  3. setImmediate(() => cb(Error('unknown')))
  4. }
  5. if (!(db.hasOwnProperty(id))) {
  6. const err = Error('not found')
  7. err.code = 'E_NOT_FOUND'
  8. setImmediate(() => cb(err))
  9. return
  10. }
  11. setImmediate(() => cb(null, db[id]))
  12. }
  13.  

What does 'c060' mean, the error message says 'unknown'. I was trying to trigger that error message, How do I trigger that error message?

Thanks!

Answers

  • this is there for the validation code to trigger, it's simulating an unknown error using a known ID. There's no need to try to trigger this yourself, but more be aware that unexpected errors need to be handled.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training