How to use the @hapi/boom.notFound function in @hapi/boom

To help you get started, we’ve selected a few @hapi/boom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JKHeadley / rest-hapi / utilities / handler-helper.js View on Github external
request.query = query

    const listResult = await _listHandler(childModel, request, Log)

    if (manyMany && association.linkingModel) {
      // EXPL: we have to manually insert the extra fields into the result
      const extraFieldData = result
      if (_.isArray(listResult.docs)) {
        for (const object of listResult.docs) {
          const data = extraFieldData.find(data => {
            return (
              data[association.model]._id.toString() === object._id.toString()
            )
          })
          if (!data) {
            throw Boom.notFound('child object not found')
          }
          const fields = data.toJSON()
          delete fields._id
          delete fields[association.model]
          object[association.linkingModel] = fields
        }
      }

      try {
        if (
          ownerModel.routeOptions &&
          ownerModel.routeOptions.getAll &&
          ownerModel.routeOptions.getAll[associationName] &&
          ownerModel.routeOptions.getAll[associationName].post
        ) {
          listResult.docs = await ownerModel.routeOptions.getAll[
github JKHeadley / rest-hapi / utilities / handler-helper.js View on Github external
if (duplicateIndex < 0) {
        // EXPL: if the association doesn't already exist, create it
        ownerObject[associationName].push(childId)
      }

      await Promise.all([
        ownerModel.findByIdAndUpdate(ownerObject._id, ownerObject, {
          runValidators: config.enableMongooseRunValidators
        })
      ])
    } else {
      throw Boom.badRequest('Association type incorrectly defined.')
    }
  } else {
    throw Boom.notFound('Child object not found.')
  }
}
github callstack / haul / packages / haul-core / src / server / setupCompilerRoutes.ts View on Github external
h: Hapi.ResponseToolkit,
  {
    filename,
    bundleType,
    bundleNames,
  }: { filename: string; bundleType?: string; bundleNames?: string[] },
  result: {
    file?: any;
    errors: string[];
    mimeType: string;
  }
) {
  if (result.errors) {
    return h.response({ errors: result.errors }).code(500);
  } else if (!result.file) {
    return Boom.notFound(`File ${filename} not found`);
  }

  let file;
  if (bundleType === 'delta') {
    // We have a bundle, but RN is expecting a delta bundle.
    // Convert full bundle into the simplest delta possible.
    // This will load slower in RN, but it won't error, which is
    // nice for automated use-cases where changing the dev setting
    // is not possible.
    file = createDeltaBundle(result.file.toString());
  } else {
    file =
      result.file.type === 'Buffer'
        ? Buffer.from(result.file.data)
        : result.file;
  }
github JKHeadley / rest-hapi / utilities / handler-helper.js View on Github external
if (config.enableSoftDelete && config.filterDeletedEmbeds) {
          // EXPL: remove soft deleted documents from populated properties
          filterDeletedEmbeds(result, {}, '', 0, Log)
        }

        if (flatten && $embed) {
          flattenEmbeds(result, associations, $embed)
        }
      }

      Log.log('Result: %s', JSON.stringify(result))

      return result
    } else {
      throw Boom.notFound('No resource was found with that id.')
    }
  } catch (err) {
    handleError(err, null, null, Log)
  }
}
github superchargejs / framework / test / unit / auth / session-scheme.js View on Github external
validate: async () => {
        throw Boom.notFound('User not found')
      }
    })
github jedireza / frame / server / api / admin-groups.js View on Github external
handler: async function (request, h) {

            const id = request.params.id;
            const update = {
                $set: {
                    permissions: request.payload.permissions
                }
            };
            const adminGroup = await AdminGroup.findByIdAndUpdate(id, update);

            if (!adminGroup) {
                throw Boom.notFound('AdminGroup not found.');
            }

            return adminGroup;
        }
    });
github ipfs / js-ipfs / src / http / api / resources / dht.js View on Github external
async handler (request, h) {
    const ipfs = request.server.app.ipfs
    const { arg } = request.query
    let res

    try {
      res = await ipfs.dht.findPeer(arg)
    } catch (err) {
      if (err.code === 'ERR_LOOKUP_FAILED') {
        throw Boom.notFound(err.toString())
      } else {
        throw Boom.boomify(err, { message: err.toString() })
      }
    }

    return h.response({
      Responses: [{
        ID: res.id.toB58String(),
        Addrs: res.multiaddrs.toArray().map((a) => a.toString())
      }],
      Type: 2
    })
  }
}
github ArkEcosystem / core / packages / core-api / src / handlers / transactions / controller.ts View on Github external
public async showUnconfirmed(request: Hapi.Request, h: Hapi.ResponseToolkit) {
        const transaction: Interfaces.ITransaction = this.transactionPool.getTransaction(request.params.id);

        if (!transaction) {
            return Boom.notFound("Transaction not found");
        }

        const data = { id: transaction.id, serialized: transaction.serialized.toString("hex") };

        return super.respondWithResource(data, "transaction", (request.query.transform as unknown) as boolean);
    }
github superchargejs / framework / console / stubs / make / auth / models / user.js View on Github external
static async findByEmailOrFail (email) {
    return this
      .findOne({ email })
      .orFail(Boom.notFound(null, { email: 'Email address is not registered' }))
  }