How to use the boom 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 / core / server / http / router / response_adapter.ts View on Github external
private toError(kibanaResponse: KibanaResponse) {
    const { payload } = kibanaResponse;
    // we use for BWC with Boom payload for error responses - {error: string, message: string, statusCode: string}
    const error = new Boom('', {
      statusCode: kibanaResponse.status,
    });

    error.output.payload.message = getErrorMessage(payload);
    error.output.payload.attributes = getErrorAttributes(payload);

    const headers = kibanaResponse.options.headers;
    if (headers) {
      // Hapi typings for header accept only strings, although string[] is a valid value
      error.output.headers = headers as any;
    }

    return error;
  }
}
github elastic / kibana / x-pack / legacy / plugins / epm / server / registry / requests.ts View on Github external
export async function getResponse(url: string): Promise {
  try {
    const response = await fetch(url);
    if (response.ok) {
      return response;
    } else {
      throw new Boom(response.statusText, { statusCode: response.status });
    }
  } catch (e) {
    throw Boom.boomify(e);
  }
}
github samtecspg / articulate / api / lib / routes / agent / agent.converse.route.js View on Github external
const {
                [PARAM_TEXT]: text,
                [PARAM_TIMEZONE]: timezone,
                [PARAM_SESSION]: sessionId,
                ...rest
            } = request.payload;

            const {
                [PARAM_DEBUG]: debug
            } = request.query;

            try {
                return await agentService.converse({ id: agentId, text, timezone, sessionId, debug, additionalKeys: rest });
            }
            catch ({ message, statusCode }) {
                return new Boom(message, { statusCode });
            }
        }
    }
github samtecspg / articulate / api / lib / routes / settings / settings.find-by-name.route.js View on Github external
handler: async (request) => {

            const { settingsService } = await request.services();
            const { [PARAM_NAME]: name } = request.params;
            try {
                return await settingsService.findByName({ name });
            }
            catch ({ message, statusCode }) {

                return new Boom(message, { statusCode });
            }
        }
    }
github samtecspg / articulate / api / lib / routes / agent / agent.find-setting-by-name.route.js View on Github external
handler: async (request) => {

            const { agentService } = await request.services();
            const {
                [PARAM_AGENT_ID]: id,
                [PARAM_NAME]: name
            } = request.params;
            try {
                return await agentService.findSettingByName({ id, name });
            }
            catch ({ message, statusCode }) {
                return new Boom(message, { statusCode });
            }
        }
    }
github samtecspg / articulate / api / lib / routes / global / global.search-by-field.route.js View on Github external
handler: async (request) => {

                const { globalService } = await request.services();
                const {
                    [PARAM_FIELD]: field,
                    [PARAM_VALUE]: value
                } = request.params;
                try {
                    return await globalService.searchByField({ field, value, model: ROUTE_TO_MODEL[ROUTE] });
                }
                catch ({ message, statusCode }) {

                    return new Boom(message, { statusCode });
                }
            }
        }
github samtecspg / articulate / api / lib / routes / agent / agent.create-post-format.route.js View on Github external
handler: async (request) => {

            const { agentService } = await request.services();
            const { [PARAM_AGENT_ID]: id } = request.params;
            try {
                return await agentService.createPostFormat({ id, postFormatData: request.payload });
            }
            catch ({ message, statusCode }) {
                return new Boom(message, { statusCode });
            }
        }
    }
github samtecspg / articulate / api / lib / routes / document / document.create.route.js View on Github external
handler: async (request) => {

            const { documentService } = await request.services();

            try {
                return await documentService.create({ data: request.payload });
            }
            catch ({ message, statusCode }) {

                return new Boom(message, { statusCode });
            }
        }
    }
github samtecspg / articulate / api / lib / routes / context / context.remove-frames-by-session-and-frame.route.js View on Github external
handler: async (request, h) => {

            const { contextService } = await request.services();
            const { [PARAM_SESSION]: sessionId, [PARAM_FRAME]: frameId } = request.params;
            try {
                await contextService.removeFramesBySessionIdAndFrameId({ sessionId, frameId });
                return h.continue;
            }
            catch ({ message, statusCode }) {

                return new Boom(message, { statusCode });
            }
        }
    }