* formatterError is used to handle any case where we were unable to * properly format the provided body * * @private * @function formatterError * @param {Response} res - response * @param {Error} err - error * @param {String} [msg] - custom log message * @returns {Response} response
(res, err, msg)
| 898 | * @returns {Response} response |
| 899 | */ |
| 900 | function formatterError(res, err, msg) { |
| 901 | // If the user provided a non-success error code, we don't want to |
| 902 | // mess with it since their error is probably more important than |
| 903 | // our inability to format their message. |
| 904 | if (res.statusCode >= 200 && res.statusCode < 300) { |
| 905 | res.statusCode = err.statusCode; |
| 906 | } |
| 907 | |
| 908 | if (typeof msg !== 'string') { |
| 909 | msg = 'error retrieving formatter'; |
| 910 | } |
| 911 | |
| 912 | res.log.warn( |
| 913 | { |
| 914 | req: res.req, |
| 915 | err: err |
| 916 | }, |
| 917 | msg |
| 918 | ); |
| 919 | |
| 920 | return flush(res); |
| 921 | } |
| 922 | |
| 923 | module.exports = patch; |