How to use the boom.isBoom function in boom

To help you get started, we’ve selected a few 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 elastic / kibana / x-pack / legacy / plugins / siem / server / lib / detection_engine / routes / utils.ts View on Github external
export const transformError = (err: Error & { statusCode?: number }) => {
  if (Boom.isBoom(err)) {
    return err;
  } else {
    if (err.statusCode != null) {
      return new Boom(err.message, { statusCode: err.statusCode });
    } else if (err instanceof TypeError) {
      // allows us to throw type errors instead of booms in some conditions
      // where we don't want to mingle Boom with the rest of the code
      return new Boom(err.message, { statusCode: 400 });
    } else {
      // natively return the err and allow the regular framework
      // to deal with the error when it is a non Boom
      return err;
    }
  }
};
github elastic / kibana / src / plugins / home / server / services / sample_data / routes / list.ts View on Github external
});
          if (count === 0) {
            sampleDataset.status = NOT_INSTALLED;
            return;
          }
        } catch (err) {
          sampleDataset.status = UNKNOWN;
          sampleDataset.statusMsg = err.message;
          return;
        }
      }
      try {
        await context.core.savedObjects.client.get('dashboard', sampleDataset.overviewDashboard);
      } catch (err) {
        // savedObjectClient.get() throws an boom error when object is not found.
        if (isBoom(err) && err.output.statusCode === 404) {
          sampleDataset.status = NOT_INSTALLED;
          return;
        }

        sampleDataset.status = UNKNOWN;
        sampleDataset.statusMsg = err.message;
        return;
      }

      sampleDataset.status = INSTALLED;
    });
github roblav96 / robinhood.tools / src / common / http.ts View on Github external
}).catch(function(error) {
		let reject = boom.isBoom(error) && [401, 500].includes(error.output.statusCode)
		if (!reject && config.retries > 0) {
			config.retries--
			if (!config.silent && process.env.DEVELOPMENT && process.env.SERVER) {
				console.warn('retry Error ->', config, error)
			}
			if (process.env.CLIENT) global.cookies();
			return clock.toPromise(config.retryTick).then(() => send(config))
		}
		return Promise.reject(error)
	})
}
github Streampunk / beamengine / app.js View on Github external
.use(async (ctx, next) => {
    try {
      await next();
      if ((ctx.status === 404) || (ctx.body === undefined)) {
        ctx.body = { statusCode: 404, error: 'Not Found',
          message: 'Resource not found.' };
        ctx.status = 404;
      }
    } catch (err) {
      if (Boom.isBoom(err)) {
        ctx.response.headers = err.output.headers;
        ctx.body = err.output.payload;
        ctx.status = err.output.statusCode;
      } else {
        ctx.status = 500;
        ctx.body = { statusCode: ctx.status, error: 'Internal Server Error',
          message: err.message };
      }
      console.error(err.stack);
    }
  })
  .use(jobCatcher)
github jsless / ipx / src / ipx.js View on Github external
operations.forEach(({ operation, args }) => {
      try {
        sharp = operation.handler(this, sharp, ...args)
      } catch (e) {
        if (Boom.isBoom(e)) {
          throw e
        }
        console.error(e + '')
        throw Boom.internal()
      }
    })
    const data = await sharp.toBuffer()
github elastic / kibana / x-pack / plugins / spaces / server / lib / copy_to_spaces / lib / create_empty_failure_response.ts View on Github external
const errorMessages: Array = (errors || []).map(error => {
    if (Boom.isBoom(error as any)) {
      return (error as Boom).output.payload as Payload;
    }
    return error as SavedObjectsImportError;
  });
github elastic / kibana / src / core / server / http / router / error_wrapper.ts View on Github external
return async (
    context: RequestHandlerContext,
    request: KibanaRequest,
    response: KibanaResponseFactory
  ) => {
    try {
      return await handler(context, request, response);
    } catch (e) {
      if (Boom.isBoom(e)) {
        return response.customError({
          body: e.output.payload,
          statusCode: e.output.statusCode,
          headers: e.output.headers,
        });
      }
      throw e;
    }
  };
};
github elastic / kibana / x-pack / plugins / security / server / errors.ts View on Github external
export function getErrorStatusCode(error: any): number {
  return Boom.isBoom(error) ? error.output.statusCode : error.statusCode || error.status;
}
github elastic / kibana / x-pack / legacy / plugins / spaces / server / lib / errors.ts View on Github external
export function wrapError(error: any) {
  if (isBoom(error)) {
    return error;
  }

  return boomify(error, { statusCode: error.status });
}
github elastic / kibana / x-pack / legacy / plugins / code / server / distributed / multinode / code_node_adapter.ts View on Github external
handler: async (req: Request) => {
          const { context, params } = req.payload as RequestPayload;
          this.log.debug(`Receiving RPC call ${req.url.path} ${util.inspect(params)}`);
          const endpoint: Endpoint = {
            toContext(): RequestContext {
              return context;
            },
          };
          try {
            const data = await serviceMethodMap[method](endpoint, params);
            return { data };
          } catch (e) {
            if (!Boom.isBoom(e)) {
              throw Boom.boomify(e, { statusCode: 500 });
            } else {
              throw e;
            }
          }
        },
      });