@intuitionrobotics/thunderstorm
Version:
77 lines • 3.2 kB
JavaScript
/*
* Thunderstorm is a full web app framework!
*
* Typescript & Express backend infrastructure that natively runs on firebase function
* Typescript & React frontend infrastructure
*
* Copyright (C) 2020 Intuition Robotics
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {} from "./server-api.js";
import { ApiException } from "../../exceptions.js";
import {} from "./HttpServer.js";
import { __stringify, _keys } from "@intuitionrobotics/ts-common";
const _propsResolver = async () => {
return {};
};
export function DefaultApiErrorMessageComposer(headersToAttach = [], propsResolver = _propsResolver) {
return async (requestData, error) => {
const { headers, query, url, body } = requestData;
const props = await propsResolver(requestData);
let slackMessage = "";
slackMessage += `${error ? error.responseCode : "000"} - ${url} \n\n`;
const propsAsString = _keys(props).reduce((toRet, key) => {
return `${toRet} ${key}: ${props[key]}\n`;
}, "");
if (props && Object.keys(props).length > 0)
slackMessage += `App Data:\n${propsAsString}\n`;
if (error) {
const cause = error.cause || error;
if (cause && cause.stack) {
slackMessage += `${cause.stack
.replace(/\/srv\/dist\//g, '@')
.replace(/\/srv\/node_modules/g, '')
.replace(/\\n/g, `\n`)
.replace(/\\"/g, `"`)
.replace(/\\t/g, '')
.replace(/\/@intuitionrobotics/g, '')}\n`;
slackMessage += "--------------------------------------------------------------------------------------\n";
}
}
const _headers = _keys(headers).reduce((toRet, key) => {
if (headersToAttach.includes(key))
toRet[key] = headers[key];
return toRet;
}, {});
if (_headers && Object.keys(_headers).length > 0)
slackMessage += `Headers: ${__stringify(_headers)}\n`;
else
slackMessage += "Headers: -- No Included Headers --\n";
if (query) {
if (query && Object.keys(query).length > 0)
slackMessage += `Query: ${__stringify(query, true)}\n`;
else
slackMessage += "Query: -- No Query --\n";
}
if (body) {
if (body && Object.keys(body).length > 0)
slackMessage += `Body: ${__stringify(body)}\n`;
else
slackMessage += "Body: -- No Body --\n";
}
return slackMessage;
};
}
;
//# sourceMappingURL=server-errors.js.map