Welcome to mirror list, hosted at ThFree Co, Russian Federation.

response_message_parser.js « utils « invite_members « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: db8ac303dc47237280c65d7f28ff22c4a489031b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { isString } from 'lodash';

function responseKeyedMessageParsed(keyedMessage) {
  try {
    const keys = Object.keys(keyedMessage);
    const msg = keyedMessage[keys[0]];

    return msg;
  } catch {
    return '';
  }
}

export function responseMessageFromError(response) {
  if (!response?.response?.data) {
    return '';
  }

  const {
    response: { data },
  } = response;

  return data.error || data.message?.error || data.message || '';
}

export function responseMessageFromSuccess(response) {
  if (!response?.data) {
    return '';
  }

  const { data } = response;

  if (data.message) {
    const { message } = data;

    if (isString(message)) {
      return message;
    }

    return responseKeyedMessageParsed(message);
  }

  return data.error || '';
}