carry out statusCodeType detection

This commit is contained in:
Roman Hotsiy 2015-11-23 22:27:55 +02:00
parent 4a53a35770
commit 16570984e0
2 changed files with 15 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import {RedocComponent, BaseComponent} from '../base';
import JsonPointer from '../../utils/JsonPointer';
import {Tabs, Tab} from '../../common/components/Tabs/tabs';
import SchemaSample from '../SchemaSample/schema-sample';
import {statusCodeType} from '../../utils/helpers';
function isNumeric(n) {
@ -42,14 +43,7 @@ export default class ResponsesSamples extends BaseComponent {
}
resp.code = respCode;
resp.type = 'success';
if (respCode >= 300 && respCode < 400) {
resp.type = 'redirect';
} else if (respCode > 400) {
resp.type = 'error';
} else if (respCode < 100) {
resp.type = 'info';
}
resp.type = statusCodeType(resp.code);
return resp;
})
.filter(response => hasExample(response));

13
lib/utils/helpers.js Normal file
View File

@ -0,0 +1,13 @@
'use strict';
export function statusCodeType(statusCode) {
let res = 'success';
if (statusCode >= 300 && statusCode < 400) {
res = 'redirect';
} else if (statusCode > 400) {
res = 'error';
} else if (statusCode < 100) {
res = 'info';
}
return res;
}