mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
refactor(): adjust coding style
This commit is contained in:
@@ -3,14 +3,26 @@ import { createHttpExceptionBody } from '../../utils/http-exception-body.util';
|
|||||||
|
|
||||||
describe('createHttpExceptionBody', () => {
|
describe('createHttpExceptionBody', () => {
|
||||||
it('should return pre-defined body if message is string', () => {
|
it('should return pre-defined body if message is string', () => {
|
||||||
expect(createHttpExceptionBody('message', 'error', 200)).to.eql({ message: 'message', error: 'error', statusCode: 200 });
|
expect(createHttpExceptionBody('message', 'error', 200)).to.eql({
|
||||||
|
message: 'message',
|
||||||
|
error: 'error',
|
||||||
|
statusCode: 200,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should override pre-defined body if message is object', () => {
|
it('should override pre-defined body if message is object', () => {
|
||||||
expect(createHttpExceptionBody({ test: 'object' }, 'error', 200)).to.eql({ test: 'object' });
|
expect(createHttpExceptionBody({ test: 'object' }, 'error', 200)).to.eql({
|
||||||
|
test: 'object',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not override pre-defined body if message is array', () => {
|
it('should not override pre-defined body if message is array', () => {
|
||||||
expect(createHttpExceptionBody(['a', 'random', 'array'], 'error', 200)).to.eql({ message: ['a', 'random', 'array'], error: 'error', statusCode: 200 });
|
expect(
|
||||||
|
createHttpExceptionBody(['a', 'random', 'array'], 'error', 200),
|
||||||
|
).to.eql({
|
||||||
|
message: ['a', 'random', 'array'],
|
||||||
|
error: 'error',
|
||||||
|
statusCode: 200,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ export const createHttpExceptionBody = (
|
|||||||
if (!message) {
|
if (!message) {
|
||||||
return { statusCode, error };
|
return { statusCode, error };
|
||||||
}
|
}
|
||||||
return isObject(message) && !Array.isArray(message) ? message : { statusCode, error, message };
|
return isObject(message) && !Array.isArray(message)
|
||||||
|
? message
|
||||||
|
: { statusCode, error, message };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user